home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / lisa / usr / lib / LST / libLSTall next >
Encoding:
Text File  |  2002-11-15  |  252.4 KB  |  10,864 lines

  1. # libLSTall global functions shared between several scripts
  2. #
  3. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  4. # Copyright (C) 1998-1999 Ralf Flaxa, Caldera (Deutschland) GmbH,
  5. #                         Erlangen, Germany
  6. #
  7. # $Id: libLSTall,v 3.206 1999/05/09 21:18:41 rf Exp $
  8. #
  9.  
  10. #
  11. # global settings (should be moved to lst.cnf)
  12. #
  13.  
  14. # first it is in MB (for convenience)
  15. SPARESPACE=5
  16. # from now on its in Bytes (for granularity)
  17. SPARESPACE="`do_calc $SPARESPACE \* 1048576`"
  18. NUM_DOINST=0
  19. ROOT_INITIALIZED=0
  20. touch $FILE_VALUES_SEL
  21.  
  22. INSTALL_MODE=OpenLinux
  23.  
  24. Is_SPARC()
  25. {
  26.     if [ "`uname -m`" = "sparc" ]; then
  27.         return 0
  28.     else
  29.         return 1
  30.     fi
  31. }
  32.  
  33. if Is_SPARC ; then
  34.     RPMBINEXT=sparc
  35. else
  36.     RPMBINEXT=i386
  37.     RPMBINEXT2=i486    # bug 84 - jwc
  38.     RPMBINEXT3=i586
  39.     RPMBINEXT4=noarch
  40. fi
  41.  
  42. case $INSTALL_MODE in
  43. LST)
  44.   # LST settings
  45.   INSTALL_MODE=LST
  46.   CONF_INSTALL_PATH_SRC=/lst_22
  47.   PKGEXT=rpm
  48.   ;;
  49. COL)
  50.   # LST settings
  51.   INSTALL_MODE=LST
  52.   CONF_INSTALL_PATH_SRC=/col
  53.   PKGEXT=rpm
  54.   ;;
  55. OpenLinux)
  56.   # LST settings
  57.   INSTALL_MODE=OpenLinux
  58.   CONF_INSTALL_PATH_SRC=/col
  59.   PKGEXT=rpm
  60.   ;;
  61. esac
  62.  
  63.  
  64. #
  65. # libAnalyse
  66. #
  67.  
  68. Store_Detected_Info()
  69. {
  70.   local cd1_dev
  71.  
  72.   # we store all detected hardware infos in /etc/system.cnf as default
  73.   sysinfo --cdrom --var > /dev/null 2> /tmp/cdrom
  74.   if [ -s /tmp/cdrom ]; then
  75.     cd1_dev="`cut -d':' -f 2 /tmp/cdrom | sed -n '1p'`"
  76.     if [ -n "$cd1_dev" ]; then
  77.       case $cd1_dev in
  78.       /dev/sr0)
  79.         cd1_dev=/dev/scd0
  80.         ;;
  81.       /dev/sr1)
  82.         cd1_dev=/dev/scd1
  83.         ;;
  84.       esac
  85.       set_val CONF_CD1_DEV "$cd1_dev"
  86.     fi
  87.   fi
  88.   return 0
  89. }
  90.  
  91. #
  92. # libModule
  93. #
  94.  
  95. Show_Hardware_Found()
  96. {
  97.   local tmpfile=/tmp/LST/ans
  98.   local what="HARDWARE"
  99.  
  100.   if [ $# -gt 0 -a "$1" = "generic" ]; then
  101.     what="HARDWARE_GENERIC"
  102.   fi
  103.  
  104.   Info ":INFO_ANALYSE_RUNNING:"
  105.   sysinfo --notitle --short > $tmpfile
  106.   if [ ! -s $tmpfile ]; then
  107.     Msg2 HARDWARE_NOT_FOUND || return 1
  108.     return 0
  109.   fi
  110.   Browse2 $tmpfile ${what}_FOUND || return 1
  111.   return 0
  112. }
  113.  
  114. Warn_Autoprobe_Dangerous()
  115. {
  116.   Msg2 AUTOPROBE_DANGEROUS || return 1
  117.   return 0
  118. }
  119.  
  120. Do_Autoprobe()
  121. {
  122.   local what=
  123.   local how=
  124.  
  125.   # CD probelists (sbpcd takes too much time)
  126.   local cd_probelist_kernel="cdu31a mcd mcdx sbpcd aztcd sonycd535 gscd arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd cm206 optcd sjcd isp16"
  127.   local cd_probelist="cdu31a mcd mcdx aztcd sonycd535 gscd arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd cm206 optcd sjcd isp16"
  128.   local cd_probelist_cautious=""
  129.  
  130.   # SCSI probelists (g_NCR5380 hangs)
  131.   local scsi_probelist_kernel="advansys BusLogic u14-34f ultrastor aha152x aha1542 aha1740 aic7xxx fdomain in2000 g_NCR5380 NCR53c406a qlogicfas qlogicisp pas16 seagate t128 dtc tmscsim 53c7,8xx ncr53c8xx eata_dma eata_pio wd7000 eata AM53C974 ppa gdth"
  132.   local scsi_probelist="advansys BusLogic u14-34f ultrastor aha152x aha1542 aha1740 aic7xxx fdomain in2000 NCR53c406a qlogicfas qlogicisp pas16 seagate t128 dtc tmscsim 53c7,8xx ncr53c8xx eata_dma eata_pio wd7000 eata ppa gdth"
  133.   local scsi_probelist_cautious="aha1542 ncr53c8xx 53c7,8xx aic7xxx"
  134.  
  135.   # net probelists
  136.   local ether_probelist_cautious="3c59x ne2k-pci 3c509 ne"
  137.   local ether_probelist_kernel="de4x5 dgrs eepro100 epic100 hp100 ne2k-pci pcnet32 rtl8139 3c59x tulip yellowfin ac3200 smc-ultra32 at1700 smc-ultra smc9194 wd 3c503 hp hp-plus seeq8005 e2100 ne at1500 fmv18x eth16i 3c509 3c515 znet eexpress eepro depca ewrk3 apricot 3c501 3c507 3c505 de600 de620 ni52 ni65 lance tlan"
  138.   # the at1500 is part of the e2100 ?
  139.   # the 3c501 is always misdetected :-(
  140.   # the seeq8005 and znet are not modularized :-(
  141.   local ether_probelist="de4x5 dgrs eepro100 epic100 hp100 ne2k-pci pcnet32 rtl8139 3c59x tulip yellowfin ac3200 smc-ultra32 at1700 smc-ultra smc9194 wd 3c503 hp hp-plus e2100 ne fmv18x eth16i 3c509 3c515 eexpress eepro depca ewrk3 apricot 3c507 3c505 ni52 ni65 lance tlan atp de600 de620"
  142.  
  143.   local driver=
  144.   local modparam=
  145.   local all=1
  146.   local retval=
  147.   local success=
  148.  
  149.   what="$1"
  150.   shift 1
  151.  
  152.   case $what in
  153.   all)
  154.     # simulate full kernel autoprobing by load & test of all modules
  155.     # first we probe for CDROMs, then for SCSI hosts and last for ethernet
  156.     probelist="$cd_probelist $scsi_probelist $ether_probelist"
  157.     probelist_cautious="$cd_probelist_cautious $scsi_probelist_cautious $ether_probelist_cautious"
  158.     ;;
  159.   CD)
  160.     probelist="$cd_probelist"
  161.     probelist_cautious="$cd_probelist_cautious"
  162.     ;;
  163.   SCSI)
  164.     probelist="$scsi_probelist"
  165.     probelist_cautious="$scsi_probelist_cautious"
  166.     ;;
  167.   NET)
  168.     probelist="$ether_probelist"
  169.     probelist_cautious="$ether_probelist_cautious"
  170.     ;;
  171.   esac
  172.  
  173.   if [ $# -gt 0 -a "$1" = "cautious" ]; then
  174.     probelist="$probelist_cautious"
  175.     all=0
  176.   fi
  177.  
  178.   Info ":INFO_AUTOPROBE_RUNNING:"
  179.  
  180.   for driver in $probelist ; do
  181.     modparam=
  182.     if [ "$driver" = "ne" ]; then
  183.       # NE2000 cards need an io parameter. 0x300 is very common.
  184.       modparam="io=0x300"
  185.     fi
  186.     Debug "probing ${driver} driver:"
  187.     Do_Load_Module_mini --silent $driver $modparam
  188.     retval=$?
  189.     if [ $retval -eq 0 ]; then
  190.       success=1
  191.     fi
  192.   done
  193.   if [ -n "$success" ]; then
  194.     return 0
  195.   else
  196.     return 1
  197.   fi
  198. }
  199.  
  200. Ask_Autoprobe()
  201. {
  202.   local what="AUTOPROBE"
  203.  
  204.   if [ $# -gt 0 -a "$1" = "cautious" ]; then
  205.     what="AUTOPROBE_CAUTIOUS"
  206.   fi
  207.   Ask bool ${what} y || return 1
  208.   return 0
  209. }
  210.  
  211. Ask_Hardware_Sufficient()
  212. {
  213.   local what="HARDWARE"
  214.   local defval=y
  215.  
  216.   if [ $# -gt 0 -a "$1" = "generic" ]; then
  217.     what="HARDWARE_GENERIC"
  218.     defval=n
  219.   fi
  220.   Ask bool ${what}_SUFFICIENT $defval || return 1
  221.   return 0
  222. }
  223.  
  224. Find_Module()
  225. {
  226.   if [ -f $1.o ]; then return 0 ; fi
  227.   if [ -f $1.o.gz ]; then return 0 ; fi
  228.   if [ -f /floppy/$1.o ]; then return 0 ; fi
  229.   if [ -f /floppy/$1.o.gz ]; then return 0 ; fi
  230.   if [ -f /source/$1.o ]; then return 0 ; fi
  231.   return 1
  232. }
  233.  
  234.  
  235. Build_Modules_Available()
  236. {
  237.   local modpath=/lib/modules/`uname -r`
  238.   local mode="$1"
  239.   local goal="$2"
  240.   local driver=
  241.   local modparam=
  242.   local subdir=
  243.   local list=
  244.   local scsi_support="scsi_mod sd_mod sg sr_mod st"
  245.   local scsi_driver="aha152x aha1542 aha1740 aic7xxx advansys AM53C974 BusLogic tmscsim dtc eata eata_dma eata_pio fdomain gdth in2000 g_NCR5380 ppa in2000 NCR53c406a 53c7,8xx ncr53c8xx pas16 qlogic qlogicfas qlogicisp seagate t128 ultrastor u14-34f wd7000"
  246.   local cdrom_driver="aztcd cdrom gscd hitcd isp16 cm206 sbpcd mcd mcdx optcd sjcd cdu31a sonycd535 arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd"
  247.   local net_support="8390 bsd_comp depca dlci dummy eql new_tunnel plip ppp sdla slhc slip"
  248.   local net_driver="3c501 3c503 3c505 3c507 3c509 3c59x ac3200 apricot arcnet at1700 atp de4x5 de600 de620 depca dgrs e2100 eepro eepro100 eexpress eth16i ewrk3 fmv18x hp hp-plus hp100 ibmtr lance ne ne2k-pci ni52 ni65 pcnet32 rtl8139 smc9194 smc-ultra smc-ultra32 tlan tulip wd yellowfin"
  249.   local fs_driver="binfmt_aout binfmt_elf binfmt_java ext ext2 hpfs isofs ncpfs nfs smbfs sysv ufs vfat xiafs"
  250.  
  251.  
  252.   case $goal in
  253.   FS)
  254.     list="$fs_driver"
  255.     modpath=$modpath/fs
  256.     ;;
  257.   CD)
  258.     list="$cdrom_driver"
  259.     modpath=$modpath/cdrom
  260.     ;;
  261.   SCSI)
  262.     # list="$scsi_support $scsi_driver"
  263.     list="$scsi_driver"
  264.     modpath=$modpath/scsi
  265.     ;;
  266.   NET)
  267.     # list="$net_support $net_driver"
  268.     list="$net_driver"
  269.     modpath=$modpath/net
  270.     ;;
  271.   ANY)
  272.     echo "\"DONE\" \":MENU_BACK:\" \\"
  273.     Build_MODULES_AVAILABLE
  274.     return 0
  275.     ;;
  276.   esac
  277.  
  278.   if [ "$mode" = "box" ]; then
  279.     # echo "\"NONE\" \":TYPE_${goal}_NONE:\" \\"
  280.     echo "\"DONE\" \":TYPE_${goal}_DONE:\" \\"
  281.     echo "\"AUTO\" \":TYPE_${goal}_AUTO:\" \\"
  282.   fi
  283.   for driver in $list ; do
  284.     Find_Module $modpath/$driver
  285.     if [ $? -eq 0 ]; then
  286.       if [ "$mode" = "box" ]; then
  287.     echo "\"$driver\" \":TYPE_${goal}_$driver:\" \\"
  288.       else
  289.     echo "$driver"    
  290.       fi
  291.     fi
  292.   done
  293.   if [ "$mode" = "box" ]; then
  294.     echo "\"OTHER\" \":TYPE_${goal}_OTHER:\" \\"
  295.   fi
  296. }
  297.  
  298.  
  299. Map_LILO_2_Insmod_Param()
  300. {
  301.   local lilo_param="$1"
  302.   local var1="$2"
  303.   local var2="$3"
  304.   local var3="$4"
  305.   local var4="$5"
  306.   local val1
  307.   local val2
  308.   local val3
  309.   local val4
  310.  
  311.   if [ -z "`sed -n "/^$lilo_param=/p" $FILE_BOOT_PARAMS`" ]; then
  312.     echo ""
  313.     return 1
  314.   fi
  315.  
  316.   case $lilo_param in
  317.   aztcd|gscd|cm206|sonycd535|optcd)
  318.     # for LILO and insmod the params are the same
  319.     sed -n "/^$lilo_param=/p" $FILE_BOOT_PARAMS
  320.     return 0
  321.     ;;
  322.   mcd)
  323.     sed -n '/^mcd=/s/^mcd=\([^,]*\),\(.*\)/mcd_port=\1 mcd_irq=\2/p' $FILE_BOOT_PARAMS
  324.     return 0
  325.     # mcd_port
  326.     # mcd_irq
  327.     # mitsumi_bug_93_wait
  328.     ;;
  329.   aic7xxx)
  330.     if [ -n "`sed -n '/^aic7xxx=extended,no_reset/p' $FILE_BOOT_PARAMS`" ]; then
  331.       echo "aic7xxx_extended=1 aic7xxx_no_reset=1"
  332.       return 0
  333.     fi
  334.     ;;
  335.   cdu31a)
  336.     sed -n '/^cdu31a=/s/^cdu31a=\([^,]*\),\(.*\)/cdu31a_port=\1 cdu31a_irq=\2/p' $FILE_BOOT_PARAMS
  337.     return 0
  338.     # cdu31a_port
  339.     # cdu31a_irq
  340.     # sony_pas_init
  341.     ;;
  342.   isp16)
  343.     ;;
  344.   sbpcd)
  345.     ;;
  346.   esac
  347.   return 0
  348. }
  349.  
  350. Do_Load_Module_mini()
  351. {
  352.   local silent_flag=
  353.   local ans=/tmp/LST/ans
  354.   local err=/tmp/LST/err
  355.   local modpath=/lib/modules/`uname -r`
  356.   local subpath=
  357.   local module=
  358.   local driver=
  359.   local modparam=
  360.   local modlist=/tmp/modules.initrd
  361.  
  362.   if [ $# -gt 0 -a "$1" = '--silent' ]; then
  363.     silent_flag=true
  364.     shift 1
  365.   fi
  366.  
  367.   driver="$1"
  368.   shift 1
  369.   modparam="$@"
  370.  
  371.   if [ -z "$modparam" ]; then
  372.     # check for LILO boot params
  373.     case $driver in
  374.     mcd|gscd|aztcd|cm206|cdu31a|aic7xxx|sonycd535|optcd)
  375.       modparam="`Map_LILO_2_Insmod_Param $driver`"
  376.       ;;
  377.     esac
  378.   fi
  379.  
  380.   # check whether it's already loaded
  381.   /sbin/lsmod | sed -n "/^$driver/p" > $ans
  382.   if [ -s $ans ]; then
  383.     return 0
  384.   fi
  385.  
  386.   # check whether it's available and prepare it for loading
  387.   for subpath in block cdrom fs ipv4 misc net pcmcia scsi ; do
  388.     mkdir -p $modpath/$subpath
  389.     module="$modpath/$subpath/${driver}.o"
  390.     if [ -s $module ]; then
  391.       break
  392.     elif [ -s $module.gz ]; then
  393.       gunzip $module.gz
  394.       break
  395.     elif [ -s /source/$module ]; then
  396.       module=/source/$module
  397.       break
  398.     elif [ -s /floppy/$module ]; then
  399.       module=/floppy/$module
  400.       break
  401.     elif [ -s /floppy/$module.gz ]; then
  402.       gzip -dcf /floppy/$module.gz > $module
  403.       break
  404.     fi
  405.     module=
  406.   done 
  407.  
  408.   if [ -z "$module" ]; then
  409.     if [ -z "$silent_flag" ]; then
  410.       Msg "module ${driver}.o ; :ERR_MODULE_NOT_AVAILABLE:"
  411.     fi
  412.     return 1
  413.   fi 
  414.  
  415.   while [ 1 ]; do
  416.     if [ -z "$silent_flag" ]; then
  417.       Info "module ${driver}.o ; :INFO_MODULE_LOADING:"
  418.       sleep 2
  419.     fi
  420.     Debug "trying <insmod $module $modparam> ... "
  421.     /sbin/insmod $module $modparam >$err 2>&1 && break
  422.     /sbin/rmmod $driver >/dev/null 2>&1
  423.     Debug "insmod ${driver} failed."
  424.     if [ -z "$silent_flag" ]; then
  425.       Info "module ${driver}.o ; :ERR_MODULE_LOADING_FAILED:"
  426.       sleep 3
  427.     fi
  428.     end_use $module
  429.     return 1
  430.   done
  431.   Debug "insmod ${driver} succeeded."
  432.   # FIXME: in the success case we do not compress the module any more
  433.   # end_use $module
  434.   if [ -z "$silent_flag" ]; then
  435.     Msg "module ${driver}.o ; :INFO_MODULE_LOADED:"
  436.   fi
  437.   echo "$driver" >> $modlist
  438.   mkdir -p /etc/modules/options
  439.   if [ -n "$modparam" ]; then
  440.     echo "$modparam" > /etc/modules/options/$driver
  441.   else
  442.     rm -f /etc/modules/options/$driver
  443.   fi
  444.   return 0
  445. }
  446.  
  447. Load_Default_Modules()
  448. {
  449.   local driver=
  450.  
  451.   for driver in $@ ; do
  452.     Do_Load_Module_mini --silent $driver "" || return 1
  453.   done
  454.   return 0
  455. }
  456.  
  457.  
  458. Choose_Module()
  459. {
  460.   local modpath=/lib/modules/`uname -r`
  461.   local goal="$1"
  462.   local driver=AUTO
  463.   local insmod_params=
  464.   local default_cd=""
  465.   local default_scsi="scsi_mod sd_mod sr_mod st sg"
  466.   local default_ether="8390"
  467.   local default_modules=
  468.  
  469.   case $goal in
  470.   CD)
  471.     default_modules="$default_cd"
  472.     ;;
  473.   SCSI)
  474.     default_modules="$default_scsi"
  475.     ;;
  476.   NET)
  477.     default_modules="$default_ether"
  478.     ;;
  479.   ANY)
  480.     MountModulesFloppy
  481.     ;;
  482.   esac
  483.  
  484.   Load_Default_Modules $default_modules
  485.  
  486.   while [ 1 ]; do
  487.     Ask one MODULE_LOAD --default "$driver" Build_Modules_Available box $goal || return 1
  488.     driver="$ANSWER"
  489.     insmod_params=
  490.     # if [ "$driver" = "NONE" ]; then
  491.     if [ "$driver" = "DONE" ]; then
  492.       return 0
  493.     fi
  494.     if [ "$driver" = "OTHER" ]; then
  495.       MountModulesFloppy
  496.       continue
  497.     fi
  498.     if [ "$driver" = "ne" ]; then insmod_params="io=0x300" ; fi
  499.     if [ "$driver" = "AUTO" ]; then
  500.       Ask_Autoprobe
  501.       if [ "$ANSWER" != "0" ]; then
  502.         continue
  503.       fi
  504.       Warn_Autoprobe_Dangerous || continue
  505.       Do_Autoprobe $goal || return 1
  506.       Show_Hardware_Found || continue
  507.       return 0
  508.     fi
  509.     # do not offer new features for COL 1.1 installs
  510.     if [ "`uname -r`" = "2.0.29" ]; then
  511.       Ask string MODULE_PARAM $insmod_params || continue
  512.     else
  513.       Menu_Module_Param "$driver" || continue
  514.     fi
  515.     insmod_params="$ANSWER"
  516.     Do_Load_Module_mini $driver $insmod_params || return 1
  517.     Show_Hardware_Found || continue
  518.     return 0
  519.   done
  520.   return 0
  521. }
  522.  
  523.  
  524. Build_Module_Analyse()
  525. {
  526.   cat << EOF
  527. "BACK" ":MENU_BACK:" \\
  528. "CHECK" ":INFO_HARDWARE_FOUND:" \\
  529. "LOADED" ":MENU_MODULE_SHOW_LOADED:" \\
  530. "SYSINFO" ":MENU_ANALYSE:" \\
  531. "DMESG" ":SHOW_BOOT_MSG:" \\
  532. "REPORT" ":DO_WRITE_ANALYSE_INFOS:" \\
  533. EOF
  534. }
  535.  
  536.  
  537. Menu_Module_Analyse()
  538. {
  539.   local action=CHECK
  540.  
  541.   while [ 1 ]; do
  542.     Ask menu MODULE_ANALYSE --default "$action" Build_Module_Analyse $action || return 1
  543.     action="$ANSWER"
  544.  
  545.     case $action in
  546.     BACK)
  547.       return 0
  548.       ;;
  549.     CHECK)
  550.       Show_Hardware_Found
  551.       ;;
  552.     LOADED)
  553.       Menu_Module_Show_Loaded
  554.       ;;
  555.     SYSINFO)
  556.       Show_Analyse_Info
  557.       ;;
  558.     DMESG)
  559.       Show_Boot_Msg
  560.       ;;
  561.     REPORT) 
  562.       Write_Analyse_Infos
  563.       ;;
  564.     esac
  565.   done
  566. }
  567.  
  568. Build_Module_Load()
  569. {
  570.   local subsys=
  571.  
  572.   echo "\"BACK\" \":MENU_BACK:\" \\"
  573.   for subsys in CD SCSI NET ANY ; do
  574.     echo "\"$subsys\" \":MENU_MODULE_LOAD_$subsys:\" \\"
  575.   done
  576. }
  577.  
  578.  
  579. Menu_Module_Load_mini()
  580. {
  581.   local action
  582.  
  583.   while [ 1 ]; do
  584.     action=
  585.     Ask one MODULE_LOAD --default "$action" Build_Module_Load $action || return 1
  586.     action="$ANSWER"
  587.     if [ "$action" = "BACK" ]; then
  588.       return 0
  589.     fi
  590.     Choose_Module $action || continue
  591.   done
  592. }
  593.  
  594. Build_Modules_Loaded()
  595. {
  596.   echo "\"BACK\" \":MENU_BACK:\" \\"
  597.   cat /proc/modules | do_quote
  598. }
  599.  
  600. Menu_Module_Remove_mini()
  601. {
  602.   Ask one MODULE_REMOVE Build_Modules_Loaded || return 1
  603.   if [ "$ANSWER" = "BACK" ]; then
  604.     return 0
  605.   fi
  606.   /sbin/rmmod $ANSWER || return 1
  607.   return 0
  608. }
  609.  
  610. Build_Config_Modules()
  611. {
  612.   cat << EOF
  613. "DONE" ":MENU_CONFIG_MODULES_DONE:" \\
  614. "ANALYSE" ":MENU_MODULE_ANALYSE:" \\
  615. "LOAD" ":MENU_MODULE_LOAD:" \\
  616. "REMOVE" ":MENU_MODULE_REMOVE:" \\
  617. EOF
  618. }
  619.  
  620.  
  621. Menu_Config_Modules()
  622. {
  623.   local action=CHECK
  624.  
  625.   while [ 1 ]; do
  626.     Ask menu CONFIG_MODULES --default "$action" Build_Config_Modules $action || return 1
  627.     action="$ANSWER"
  628.  
  629.     case $action in
  630.     DONE)
  631.       return 0
  632.       ;;
  633.     ANALYSE)
  634.       Menu_Module_Analyse
  635.       ;;
  636.     LOAD)
  637.       Menu_Module_Load_mini
  638.       ;;
  639.     REMOVE)
  640.       Menu_Module_Remove_mini
  641.       ;;
  642.     esac
  643.   done
  644. }
  645.  
  646. #
  647. # libInit
  648. #
  649.  
  650. InitSubsystems()
  651. {
  652.   local subsys=
  653.   local subsys_state=8
  654.  
  655.   # first try all subsystems
  656.   rm -f /tmp/subsystems
  657.   for subsys in PCMCIA SCSI NET CD ; do
  658.     echo "$subsys" >> /tmp/subsystems
  659.   done
  660.  
  661.   # load generic 8390 ethernet driver module
  662.   Load_Default_Modules 8390
  663.  
  664.   # load SCSI high level protocol driver
  665.   Load_Default_Modules scsi_mod sd_mod sr_mod st sg
  666.  
  667.   # load filesystems
  668.   Load_Default_Modules nfs isofs
  669.  
  670.   # check and load PCMCIA subsystem
  671. #  if Is_SPARC ; then
  672. #    Debug "Skipping probe for PCMCIA on SPARC!"
  673. #  else
  674. #    InitPCMCIA
  675. #  fi
  676.  
  677.   while [ 1 ]; do
  678.     subsys_state="`do_calc $subsys_state - 1`"
  679.     case $subsys_state in
  680.     0)
  681.       return 1
  682.       ;;
  683.     1)
  684.       Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  685.       Ask_Bool ABORT_INSTALL y
  686.       if [ "$ANSWER" = "0" ]; then
  687.     Do_Reboot
  688.       fi
  689.       ;;
  690.     2)
  691.       Show_Hardware_Found generic || continue
  692.       ;;
  693.     3)
  694.       Ask_Hardware_Sufficient generic || continue
  695.       if [ "$ANSWER" = "0" ]; then
  696.         # this lets us jump to Menu_Config_Modules
  697.         subsys_state=20
  698.     continue
  699.       fi
  700.       ;;
  701.     4)
  702.       Ask_Autoprobe cautious || continue
  703.       if [ "$ANSWER" != "0" ]; then
  704.         # this lets us jump to Menu_Config_Modules
  705.         subsys_state=11
  706.     continue
  707.       fi
  708.       ;;
  709.     5)
  710.       Warn_Autoprobe_Dangerous || continue
  711.       Do_Autoprobe all cautious
  712.       subsys_state="`do_calc $subsys_state + 1`"
  713.       ;;
  714.     6)
  715.       Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  716.       Ask_Bool ABORT_INSTALL y
  717.       if [ "$ANSWER" = "0" ]; then
  718.     Do_Reboot
  719.       fi
  720.       ;;
  721.     7)
  722.       Show_Hardware_Found || continue
  723.       ;;
  724.     8)
  725.       Ask_Hardware_Sufficient || continue
  726.       if [ "$ANSWER" = "0" ]; then
  727.         # this lets us jump to Menu_Config_Modules
  728.         subsys_state=20
  729.     continue
  730.       fi
  731.       subsys_state="`do_calc $subsys_state + 1`"
  732.       ;;
  733.     9)
  734.       Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  735.       Ask_Bool ABORT_INSTALL y
  736.       if [ "$ANSWER" = "0" ]; then
  737.     Do_Reboot
  738.       fi
  739.       ;;
  740.     10)
  741.       Menu_Config_Modules || continue
  742.       ;;
  743.     *)
  744.       Info ":INFO_WAIT:"
  745.       Store_Detected_Info
  746.       Get_BOOTP_Info
  747.       return 0
  748.       ;;
  749.     esac
  750.     subsys_state="`do_calc $subsys_state + 2`"
  751.   done
  752. }
  753.  
  754. #
  755. # libPCMCIA
  756. #
  757.  
  758. HasPCMCIA()
  759. {
  760.   Debug "searching for PCMCIA controllers with probe:"
  761.   prep_use PCMCIA_PROBE
  762.   /sbin/probe >/tmp/pcmcia 2>&1
  763.   if [ $? -eq 0 ]; then
  764.     Debug "probe returned with 0"
  765.     Debug "PCMCIA chip found! Asking for PCMCIA Support!"
  766.     Ask bool PCMCIA_SUPPORT y || return 1
  767.     if [ "$ANSWER" != "0" ]; then return 1 ; fi
  768.     MountModulesFloppy
  769.   else
  770.     Debug "probe returned with non 0"
  771.     Debug "No supported PCMCIA chip found! Skipping PCMCIA!"
  772.     return 1
  773.   fi
  774.   return 0
  775. }
  776.  
  777. UnpackPCMCIA()
  778. {
  779.   mkdir -p /lib/modules/`uname -r`/pcmcia
  780.  
  781.   Debug "Memory usage before PCMCIA unpack:"
  782.   free > /dev/tty8
  783.   Debug "disk usage before PCMCIA unpack:"
  784.   df > /dev/tty8
  785.  
  786.   prep_use PCMCIA
  787.  
  788.   Debug "Memory usage after PCMCIA unpack:"
  789.   free > /dev/tty8
  790.   Debug "disk usage after PCMCIA unpack:"
  791.   df > /dev/tty8
  792.   return 0
  793. }
  794.  
  795. RemovePCMCIA()
  796. {
  797.   not_use PCMCIA_PROBE
  798.   not_use PCMCIA
  799. }
  800.  
  801. InitPCMCIA()
  802. {
  803.   local pcic=
  804.   local chip=
  805.   local modpath=
  806.   local retval=1
  807.  
  808.   if [ -z "`fgrep -x PCMCIA /tmp/subsystems`" ]; then
  809.     return 0
  810.   fi
  811.  
  812.   modpath=/lib/modules/`uname -r`/pcmcia
  813.  
  814.   HasPCMCIA || return 1
  815.   UnpackPCMCIA || return 1
  816.  
  817.   # /bin/sh /etc/rc.d/rc.pcmcia
  818.   # this will be replaced by rc.pcmcia
  819.   while [ 1 ]; do
  820.     Load_Default_Modules pcmcia_core || break
  821.     # the chip should be derived automatically from the probe command
  822.     # see /tmp/pcmcia
  823.     for chip in i82365 tcic ; do
  824.       Load_Default_Modules $chip
  825.       if [ $? -eq 0 ]; then
  826.         pcic=$chip
  827.         Load_Default_Modules ds
  828.         break
  829.       fi
  830.     done
  831.     if [ -z "$pcic" ]; then break ; fi
  832.     if [ ! -s /sbin/cardmgr ]; then break ; fi
  833.     /sbin/cardmgr || break
  834.     pcic="ok"
  835.     break
  836.   done
  837.   if [ "$pcic" != "ok" ]; then
  838.     if [ -z "$pcic" ]; then
  839.       Debug "No supported PCMCIA chip found! Skipping PCMCIA!"
  840.     fi
  841.     if [ -s /var/run/cardmgr.pid ]; then
  842.       kill `cat /var/run/cardmgr.pid`
  843.       sleep 1
  844.     fi
  845.     /sbin/rmmod ds >/dev/null 2>&1 
  846.     /sbin/rmmod tcic >/dev/null 2>&1
  847.     /sbin/rmmod i82365 >/dev/null 2>&1
  848.     /sbin/rmmod pcmcia_core >/dev/null 2>&1
  849.   else
  850.     Debug "$chip PCMCIA chip detected!"
  851.     Debug "Ask to insert PCMCIA cards"
  852.     Msg ":DO_INSERT_PCMCIA_CARDS:"
  853.     retval=0
  854.   fi
  855.   # remove all PCMCIA modules from the ramdisk to save space
  856.   RemovePCMCIA
  857.   return $retval
  858. }
  859.  
  860. Set_If_Unset()
  861. {
  862.     if [ -z "`get_val $1`" ]; then
  863.         set_val $1 "$2"
  864.     fi
  865. }
  866.  
  867. Get_netprobe_Info()
  868. {
  869.   local retval
  870.   local probes="`get_val CONF_SETUP_NETPROBE_PROBES`"
  871.   local probe_hostname
  872.   local probe_gateway
  873.   local probe_nameserver
  874.   local probe_netmask
  875.   local probe_nisdomain
  876.   local probe_nisserver
  877.   local probe_string
  878.   local bpf=/tmp/netprobe.out
  879.   local debug_tty=/dev/tty7
  880.   local fqhn=
  881.   local eth0_ip=
  882.   local eth0_mask=
  883.   local eth0_bcast=
  884.   local eth0_net=
  885.   local router1_ip=
  886. # local dns_domain=
  887. # local dns_search=
  888.   local dns_server1_ip=
  889. # local dns_server2_ip=
  890. # local dns_server3_ip=
  891.   local nfs_server1_ip=
  892.   local nfs_server1_path=
  893.   local nis_domain=
  894.   local nis_server1_ip=
  895.  
  896.   if [ "`get_val CONF_SETUP_USE_NETPROBE`" != "on" ]; then return 1 ; fi
  897.   if [ -z "$probes" ]; then return 1 ; fi
  898.   if [ ! -x /usr/bin/netprobe ]; then return 1 ; fi
  899.  
  900.   Info ":INFO_NETPROBE_RUNNING: ; ; :INFO_WAIT:"
  901.   sleep 2
  902.  
  903.   # building probe_string
  904.   echo "$probes" | fgrep netmask > /dev/null
  905.   if [ $? -eq 0 ]; then
  906.     probe_netmask=true
  907.     probe_string="$probe_string -p netmask"
  908.   fi
  909.   echo "$probes" | fgrep nisdomain > /dev/null
  910.   if [ $? -eq 0 ]; then
  911.     probe_nisdomain=true
  912.     probe_string="$probe_string -p nisdomain"
  913.   fi
  914.   echo "$probes" | fgrep nameserver > /dev/null
  915.   if [ $? -eq 0 ]; then
  916.     probe_nameserver=true
  917.     probe_string="$probe_string -p nameserver"
  918.   fi
  919.   echo "$probes" | fgrep nisserver > /dev/null
  920.   if [ $? -eq 0 ]; then
  921.     probe_nisserver=true
  922.     probe_string="$probe_string -p nisserver"
  923.   fi
  924.   echo "$probes" | fgrep hostname > /dev/null
  925.   if [ $? -eq 0 ]; then
  926.     probe_hostname=true
  927.     probe_string="$probe_string -p hostname"
  928.   fi
  929.   echo "$probes" | fgrep gateway > /dev/null
  930.   if [ $? -eq 0 ]; then
  931.     probe_gateway=true
  932.     probe_string="$probe_string -p gateway"
  933.   fi
  934.  
  935.   # remark: lo and eth0 has to be up and running, so the IP address
  936.   #         has to be known
  937.  
  938.   echo "running netprobe..." > $debug_tty
  939.   /usr/bin/netprobe $probe_string > $bpf 2> $debug_tty
  940.   retval=$?
  941.  
  942.   if [ $retval -ne 0 ]; then
  943.     echo "netprobe returns with <$retval>" > $debug_tty
  944.     # return 1
  945.   fi
  946.  
  947.   if [ ! -s $bpf ]; then
  948.     echo "netprobe returns no output" > $debug_tty
  949.     return 1
  950.   fi
  951.  
  952.   echo "netprobe returns:" > $debug_tty
  953.   cat $bpf > $debug_tty
  954.  
  955.   while [ 1 ]; do
  956.     Browse2 $bpf NETPROBE_OUTPUT || return 1
  957.     Ask_Bool USE_NETPROBE_OUTPUT || continue
  958.     if [ "$ANSWER" != "0" ]; then return 1 ; fi
  959.     break
  960.   done
  961.  
  962.   fqhn="`get_val -f $bpf HOSTNAME`"
  963.   if [ -n "$probe_hostname" -a -n "$fqhn" ]; then
  964.     Set_If_Unset CONF_FQ_HOSTNAME "$fqhn"
  965.   fi
  966.  
  967.   # FIXME
  968.   eth0_ip="`get_val CONF_eth0_IP`"
  969.   eth0_net="`get_val CONF_eth0_NET`"
  970.  
  971.   eth0_mask="`get_val -f $bpf NETMASK`"
  972.   eth0_bcast="`get_val -f $bpf BROADCAST`"
  973.   if [ -n "$eth0_mask" -a -n "$eth0_ip" -a -n "$probe_netmask" ]; then
  974.       Set_If_Unset CONF_eth0_MASK "$eth0_mask"
  975.       Set_If_Unset CONF_eth0_BCAST "$eth0_bcast"
  976.  
  977.     # now reconfigure eth0 interface
  978.     ifconfig eth0 down 2> $debug_tty
  979.     ifconfig lo down 2> $debug_tty
  980.     ifconfig lo 127.0.0.1 2> $debug_tty
  981.     route add -net 127.0.0.0 2> $debug_tty
  982.     ifconfig eth0 $eth0_ip netmask $eth0_mask broadcast $eth0_bcast 2> $debug_tty
  983.     route add -net $eth0_net 2> $debug_tty
  984.   fi
  985.  
  986.   router1_ip="`get_val -f $bpf GATEWAY`"
  987.   if [ -n "$probe_gateway" -a -n "$router1_ip" ]; then
  988.     Set_If_Unset CONF_ROUTER1_IP "$router1_ip"
  989.   fi
  990.  
  991.   dns_server1_ip="`get_val -f $bpf DNSSERVER1`"
  992. # dns_server2_ip="`get_val -f $bpf DNSSRVS`"
  993. # dns_server3_ip="`get_val -f $bpf DNSSRVS`"
  994.   if [ -n "$probe_nameserver" -a -n "dns_server1_ip" ]; then
  995.     # Set_If_Unset CONF_DNS_DOMAIN "$dns_domain"
  996.     # Set_If_Unset CONF_DNS_SEARCH "$dns_search"
  997.     Set_If_Unset CONF_DNS_SERVER1_IP "$dns_server1_ip"
  998.     # Set_If_Unset CONF_DNS_SERVER2_IP "$dns_server2_ip"
  999.     # Set_If_Unset CONF_DNS_SERVER3_IP "$dns_server3_ip"
  1000.   fi
  1001.  
  1002.   nis_domain="`get_val -f $bpf NISDOMAIN`"
  1003.   if [ -n "$probe_nisdomain" -a -n "nis_domain" ]; then
  1004.     Set_If_Unset CONF_NIS_DOMAIN "$nis_domain"
  1005.   fi
  1006.  
  1007.   nis_server1_ip="`get_val -f $bpf NISSERVER1 | cut -d':' -f 1`"
  1008.   if [ -n "$probe_nisserver" -a -n "nis_server1_ip" ]; then
  1009.     Set_If_Unset CONF_NIS_SERVER1_IP "$nis_server1_ip"
  1010.   fi
  1011.  
  1012. # Set_If_Unset CONF_NFS_SERVER1_IP "$nfs_server1_ip"
  1013. # Set_If_Unset CONF_NFS_SERVER1_PATH "$nfs_server1_path"
  1014. }
  1015.  
  1016. Get_BOOTP_Info()
  1017. {
  1018.   local retval
  1019.   local bpf=/tmp/bootpc.out
  1020.   local debug_tty=/dev/tty7
  1021.   local fqhn=
  1022.   local eth0_ip=
  1023.   local eth0_mask=
  1024.   local eth0_bcast=
  1025.   local router1_ip=
  1026. # local dns_domain=
  1027. # local dns_search=
  1028.   local dns_server1_ip=
  1029. # local dns_server2_ip=
  1030. # local dns_server3_ip=
  1031.   local nfs_server1_ip=
  1032.   local nfs_server1_path=
  1033.   local nis_domain=
  1034.   local nis_server1_ip=
  1035.  
  1036.   if [ "`get_val CONF_SETUP_USE_BOOTP`" != "on" ]; then return 1 ; fi
  1037.   if [ ! -x /usr/bin/bootpc ]; then return 1 ; fi
  1038.  
  1039.   Info ":INFO_BOOTP_RUNNING: ; ; :INFO_WAIT:"
  1040.   sleep 2
  1041.   
  1042.   ifconfig eth0 down 2> $debug_tty
  1043.   ifconfig lo down 2> $debug_tty
  1044.  
  1045.   ifconfig lo 127.0.0.1 2> $debug_tty
  1046.   route add -net 127.0.0.0 2> $debug_tty
  1047.   ifconfig eth0 0.0.0.0 netmask 0.0.0.0 broadcast 0.0.0.0 2> $debug_tty
  1048.   route add -net 0.0.0.0 2> $debug_tty
  1049.  
  1050.   echo "running bootpc..." > $debug_tty
  1051.   /usr/bin/bootpc > $bpf 2> $debug_tty
  1052.   retval=$?
  1053.  
  1054.   ifconfig eth0 down 2> $debug_tty
  1055.   ifconfig lo down 2> $debug_tty
  1056.  
  1057.   if [ $retval -ne 0 ]; then
  1058.     echo "bootpc returns with <$retval>" > $debug_tty
  1059.     return 1
  1060.   fi
  1061.  
  1062.   if [ ! -s $bpf ]; then
  1063.     echo "bootpc returns no output" > $debug_tty
  1064.     return 1
  1065.   fi
  1066.  
  1067.   echo "bootpc returns:" > $debug_tty
  1068.   cat $bpf > $debug_tty
  1069.  
  1070.   while [ 1 ]; do
  1071.     Browse2 $bpf BOOTP_OUTPUT || return 1
  1072.     Ask_Bool USE_BOOTP_OUTPUT || continue
  1073.     if [ "$ANSWER" != "0" ]; then return 1 ; fi
  1074.     break
  1075.   done
  1076.  
  1077.   fqhn="`get_val -f $bpf HOSTNAME`"
  1078.   eth0_ip="`get_val -f $bpf IPADDR`"
  1079.   eth0_mask="`get_val -f $bpf NETMASK`"
  1080.   eth0_bcast="`get_val -f $bpf BROADCAST`"
  1081.   router1_ip="`get_val -f $bpf GATEWAYS | sed 's/ .*//'`"
  1082.   dns_server1_ip="`get_val -f $bpf DNSSRVS | sed 's/ .*//'`"
  1083. # dns_server2_ip="`get_val -f $bpf DNSSRVS`"
  1084. # dns_server3_ip="`get_val -f $bpf DNSSRVS`"
  1085.  
  1086.   # make life easier for us ...
  1087.   if [ -n "`echo "$fqhn" | fgrep ".lst.de"`" ]; then
  1088.     nfs_server1_ip="194.231.72.1"
  1089.     nfs_server1_path="/lst/install"
  1090.     nis_domain="LST"
  1091.     nis_server1_ip="194.231.72.1"
  1092.   # and for Caldera ...
  1093.   elif [ -n "`echo "$fqhn" | fgrep ".caldera.com"`" ]; then
  1094.     # FIXME: that is harcoded for now
  1095.     # will offer scroll menu with netprobe nfs output
  1096.     nfs_server1_ip="207.49.12.48"
  1097.     nfs_server1_path="/OpenLinux/1.2"
  1098.   fi
  1099.  
  1100.   set_val CONF_FQ_HOSTNAME "$fqhn"
  1101.   set_val CONF_eth0_IP "$eth0_ip"
  1102.   set_val CONF_eth0_MASK "$eth0_mask"
  1103.   set_val CONF_eth0_BCAST "$eth0_bcast"
  1104.   set_val CONF_ROUTER1_IP "$router1_ip"
  1105.   Set_If_Unset CONF_NFS_SERVER1_IP "$nfs_server1_ip"
  1106.   Set_If_Unset CONF_NFS_SERVER1_PATH "$nfs_server1_path"
  1107. # set_val CONF_DNS_DOMAIN "$dns_domain"
  1108. # set_val CONF_DNS_SEARCH "$dns_search"
  1109.   set_val CONF_DNS_SERVER1_IP "$dns_server1_ip"
  1110. # set_val CONF_DNS_SERVER2_IP "$dns_server2_ip"
  1111. # set_val CONF_DNS_SERVER3_IP "$dns_server3_ip"
  1112.   Set_If_Unset CONF_NIS_DOMAIN "$nis_domain"
  1113.   Set_If_Unset CONF_NIS_SERVER1_IP "$nis_server1_ip"
  1114. }
  1115.  
  1116. #######################################################################
  1117.  
  1118. # libLSTcheck check functions shared between several scripts
  1119. #
  1120. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  1121. #
  1122.  
  1123. # check arguments for a function
  1124. #
  1125. Check_Args()
  1126. {
  1127.   if [ $# -lt 3 ]; then
  1128.     Panic "Check_Args :ERR_WRONG_NUM_OF_ARGS: ($#)"
  1129.     Panic "function Check_Args (wanted 4 args, got $# args) ; args=<$@> ; :ERR_WRONG_NUM_OF_ARGS:"
  1130.     return 1
  1131.   fi
  1132.   if [ $2 -ne $3 ]; then
  1133.     Panic "function $1 (wanted $2 args, got $3 args) ; args=<$4> ; :ERR_WRONG_NUM_OF_ARGS:"
  1134.     return 1
  1135.   fi
  1136.   return 0
  1137. }
  1138.  
  1139. # test a string against a valid char list
  1140. # returns 0 if all chars of string are in the valid_char_list
  1141. # returns 1 if invalid chars are found and echos invalid chars
  1142. #
  1143. Check_Chars_Valid()
  1144. {
  1145.     local f_name=Check_Chars_Valid
  1146.     local f_args=2 # (string, validchars) ->
  1147.  
  1148.     Check_Args $f_name $f_args $# "$@" || return 255
  1149.     # Test for invalid chars
  1150.     dummy=`echo $1 | sed "s/[$2]//g"`
  1151.     if [ ! -z "$dummy" ]; then
  1152.         echo "$dummy"
  1153.         return 1
  1154.     else
  1155.         return 0
  1156.     fi
  1157. }
  1158.  
  1159. Check_Chroot()
  1160. {
  1161.     if [ "$DIR_TARGET" != "/" ]; then
  1162.         $CMD_BOX --title ":WARNING:" --msg "$1 ; :ERR_IMPOSSIBLE_WITH_CHROOT:"
  1163.         return 1
  1164.     fi
  1165.     return 0
  1166. }
  1167.  
  1168. Is_Expert()
  1169. {
  1170.     local f_name=Is_Expert
  1171.     local f_args=0 # MODE_USER ->
  1172.  
  1173.     Check_Args $f_name $f_args $# "$@" || return 255
  1174.     if [ "$MODE_USER" = "expert" ]; then
  1175.         return 0
  1176.     else
  1177.         return 1
  1178.     fi
  1179. }
  1180.  
  1181. Has_File()
  1182. {
  1183.     if [ $# -lt 1 ]; then
  1184.         Panic "missing arg to Has_File"
  1185.     fi
  1186.     if [ -s $1 ]; then
  1187.         return 0
  1188.     else
  1189.         if [ -f $1 ]; then
  1190.             Debug "$f_name: $1: file is empty."
  1191.         else
  1192.             Debug "$f_name: $1: file is not installed."
  1193.             if [ $# -gt 1 ]; then
  1194.                 Error "$2"
  1195.             fi
  1196.         fi
  1197.         return 1
  1198.     fi
  1199. }
  1200.  
  1201. # check if a file exists
  1202. #
  1203. Check_File()
  1204. {
  1205.   local f_name=Check_File
  1206.   local f_args=1 # (file) ->
  1207.  
  1208.   Check_Args $f_name $f_args $# "$@" || return 255
  1209.   if [ -f $1 ]; then
  1210.     return 0
  1211.   else
  1212.     return 1
  1213.   fi
  1214. }
  1215.  
  1216. # search for a string (exact match) in a file
  1217. #
  1218. Check_Found()
  1219. {
  1220.     local f_name=Check_Found
  1221.     local f_args=2 # (string, file) ->
  1222.  
  1223.     Check_Args $f_name $f_args $# "$@" || return 255
  1224.     if [ -z "$1" ]; then
  1225.         Debug "Check_Found: arg 1 is empty"
  1226.         return 2
  1227.     fi
  1228.     if [ -z "$2" ]; then
  1229.         Debug "Check_Found: arg 2 is empty"
  1230.         return 3
  1231.     fi
  1232.     if [ ! -s $2 ]; then
  1233.         Debug "Check_Found: $2: file empty or nonexistent"
  1234.         return 4
  1235.     fi
  1236.     fgrep -x $1 $2 >/dev/null 2>&1 || return 1
  1237.     return 0
  1238. }
  1239.  
  1240. # checks if a path is valid and sets STATUS to the type and
  1241. # and if false ERROR to an error message
  1242. #
  1243. Check_Path_Valid()
  1244. {
  1245.     local f_name=Check_Path_Valid
  1246.     local f_args=1 # (path) -> STATUS,ERROR
  1247.     export STATUS=
  1248.     export ERROR=
  1249.  
  1250.     Check_Args $f_name $f_args $# "$@" || return 255
  1251.     if [ -L $1 ]; then
  1252.         STATUS="symlink"
  1253.     elif [ -d $1 ]; then
  1254.         STATUS="directory"
  1255.     elif [ -f $1 ]; then
  1256.         STATUS="file"
  1257.     else
  1258.         ERROR="$1 ; :ERR_INVALID_PATH:"
  1259.         return 1
  1260.     fi
  1261.     return 0
  1262. }
  1263.  
  1264. # Call action_func and depending on success the corresponding func
  1265. #
  1266. Do_Action()
  1267. {
  1268.     local f_name=Do_Action
  1269.     local f_args=3 # (action_func, success_func, error_func) ->
  1270.  
  1271.     Check_Args $f_name $f_args $# "$@" || return 255
  1272.     eval $1
  1273.     if [ $? -eq 0 ]; then
  1274.         eval $2
  1275.         return 0
  1276.     else
  1277.         eval $3
  1278.         return 1
  1279.     fi
  1280. }
  1281.  
  1282. Do_Analyse_All()
  1283. {
  1284.     sysinfo --var > $FILE_TMP_MSG.tmp 2> $FILE_BOOT_DIAG.tmp 
  1285.     sed -e 's/ sr=/ scd=/g' -e 's:/dev/sr:/dev/scd:g' < $FILE_TMP_MSG.tmp > $FILE_TMP_MSG
  1286.     sed -e 's/:sr=/:scd=/g' -e 's:/dev/sr:/dev/scd:g' < $FILE_BOOT_DIAG.tmp > $FILE_BOOT_DIAG
  1287.     rm -f $FILE_BOOT_DIAG.tmp $FILE_TMP_MSG.tmp
  1288.     sleep 2
  1289. }
  1290.  
  1291. Do_Backup_File()
  1292. {
  1293.   local file=$1
  1294.  
  1295.   if [ -f $file ]; then
  1296.     cp -a $file ${file}~
  1297.   fi
  1298. }
  1299.  
  1300.  
  1301. #
  1302. # filter right edition from libLSTall
  1303. #
  1304. Do_Filter_libLSTall()
  1305. {
  1306.   local edition=$1
  1307.   local omit=
  1308.  
  1309.   case $edition in
  1310.   CND)
  1311.     omit="LST"
  1312.     ;;
  1313.   *)
  1314.     omit="CND"
  1315.     ;;
  1316.   esac
  1317.  
  1318.   sed -e '/^#%#ifdef '$omit'/,/^#%#endif '$omit'/d' \
  1319.     -e '/^#%#/d'
  1320. }
  1321.  
  1322.  
  1323. #
  1324. # filter right language and edition from libLSTtext
  1325. #
  1326. Do_Filter_libLSTtext()
  1327. {
  1328.   local edition=$1
  1329.   local lang=$2
  1330.   sed "{
  1331.     s/^${lang}-$edition> //
  1332.     s/^${lang}-x> //
  1333.     s/^x-$edition> //
  1334.     s/^x-x> //
  1335.     /^[a-z]\{2\}-[A-Za-z]\{3,5\}> /d
  1336.         /^x-[A-Za-z]\{3,5\}> /d
  1337.     /^[a-z]\{2\}-x> /d
  1338.     }"
  1339. }
  1340.  
  1341. Do_Merge_libLSTtext()
  1342. {
  1343.     local floppy_lib="$1"
  1344.     local cd_lib="$2"
  1345.     local labels_new="ASK_ETHER_REMOTE_IP_TEXT ASK_ETHER_REMOTE_IP_TITLE TYPE_CD_arcd TYPE_CD_bpcd TYPE_CD_bpmcd TYPE_CD_dscd TYPE_CD_eicd TYPE_CD_epcd TYPE_CD_kicd TYPE_CD_oicd TYPE_CD_pwcd TYPE_PARALLEL_DEV_lp0 TYPE_PARALLEL_DEV_lp1 TYPE_PARALLEL_DEV_lp2 TYPE_PRINTER_PostScript"
  1346.     local label
  1347.  
  1348.     # the libLSTtext-mini on the floppy is more up to date
  1349.     # and also may contain labels the libLSTtext CD version
  1350.     # doesn't have.
  1351.     # The trick is to keep what's in the mini version only
  1352.     # and to append the CD version
  1353.  
  1354.     # if they are the same, then take the one from the CD
  1355.     if [ "`sed -n '/^# $Id/p' $floppy_lib`" = "`sed -n '/^# $Id/p' $cd_lib`" ]; then
  1356.         cp -a $cd_lib $floppy_lib
  1357.         return 0
  1358.     fi
  1359.  
  1360.     # otherwise take the floppy header
  1361.     sed -n '1,/^:/{
  1362.         /^:/d
  1363.         p
  1364.         }' $floppy_lib > ${floppy_lib}.new
  1365.     # add the new labels
  1366.     for label in $labels_new ; do
  1367.         sed -n "/^:$label:/,/^:/{
  1368.             /^:$label:/p
  1369.             /^:/d
  1370.             p
  1371.             }" $floppy_lib >> ${floppy_lib}.new
  1372.     done
  1373.     # and append the old CD version
  1374.     cat $cd_lib >> ${floppy_lib}.new
  1375.     mv ${floppy_lib}.new $floppy_lib
  1376.     return 0
  1377. }
  1378.  
  1379. # try to lookup a short filename for a given long filename
  1380. # by a 'trans.tbl' file
  1381. #
  1382. Do_Lookup_Trans_Tbl()
  1383. {
  1384.   local dir="`dirname $1`"
  1385.   local TransTblFile="$dir/trans.tbl"
  1386.   local LongName="`basename $1`"
  1387.   local PkgRegexProof="`echo "$LongName" | sed 's/\+/\\\+/g'`"
  1388.   local ShortName=
  1389.  
  1390.   Debug "Called Do_Lookup_Trans_Tbl $1"
  1391.   if [ ! -f $TransTblFile ]; then
  1392.     Debug "trans.tbl file $TransTblFile not found"
  1393.     return 1
  1394.   fi
  1395.  
  1396.   # using cut to circumvent broken sed
  1397.   ShortName="`sed -n '/[     ]'${PkgRegexProof}'$/p' $TransTblFile | cut -c 3-14`"
  1398.   Debug "ShortName=<$ShortName>"
  1399.   if [ ! -z "$ShortName" -a -r "$dir/$ShortName" ]; then
  1400.     export ANSWER="$dir/$ShortName"
  1401.     return 0
  1402.   fi
  1403.   return 1
  1404. }
  1405.  
  1406. Do_Clear_Screen()
  1407. {
  1408.     echo "c"
  1409. }
  1410.  
  1411. # Do_Config_Update ( CONFIG_FILE )
  1412. #
  1413. #    Reset config file with current values
  1414. #
  1415. Do_Config_Update()
  1416. {
  1417.     # Wipe out old configuration and prepare new    
  1418.     ( sed -n "
  1419.         /^$/ {
  1420.             s/^/echo/p
  1421.             d
  1422.         }
  1423.         /^#/ {
  1424.             s/^\(.*\)/echo \'\1\'/p
  1425.             d
  1426.         }
  1427.         s/^\(.*\)=\(.*\)/echo \"\1=\$\1\"/p
  1428.     " ) < $1 > $1.$$.tmp
  1429.     if [ $? != 0 ]; then
  1430.         Panic "Do_Config_Update: error in sed call"
  1431.         return 1
  1432.     fi
  1433.  
  1434.     # Analyse system to get valid settings
  1435.     # Analyse_System -all
  1436.  
  1437.     # Erase old config file
  1438.     . $1.$$.tmp >> $1.$$.tmp2
  1439.     rm -f $1.$$.tmp
  1440.     # Requote Variables
  1441.     sed '/^[^#]/s/^\(.*\)=\(.*\)/\1=\"\2\"/' < $1.$$.tmp2 > $1
  1442.     rm -f $1.$$.tmp2
  1443. }
  1444.  
  1445. Do_Prompt()
  1446. {
  1447.     echo -n "press any key to continue"
  1448.     get_key > /dev/null
  1449.     echo
  1450. }
  1451.  
  1452. # Do_Store ( VAR VAL [CONFIG_FILE] )
  1453. #
  1454. Do_Store()
  1455. {
  1456.     local conf_file=$FILE_SYSTEM_CONF
  1457.  
  1458.     if [ $# -eq 3 ]; then
  1459.         conf_file=$3
  1460.     elif [ $# -ne 2 ]; then
  1461.         Panic "got $# instead of 2 or 3 args!"
  1462.     fi
  1463.  
  1464.     # store in config file
  1465.     set_val -f $conf_file "$1" "$2"
  1466.     echo "$1=\"$2\"" > $FILE_TMP_VAL
  1467.     . $FILE_TMP_VAL
  1468.     rm -f $FILE_TMP_VAL
  1469. }
  1470.  
  1471. Do_Symlink()
  1472. {
  1473.     local f_name=Do_Symlink
  1474.     local f_args=2 # (orig, symlink) ->
  1475.     local dir1
  1476.     local dir2
  1477.     local file1
  1478.     local file2
  1479.  
  1480.     Check_Args $f_name $f_args $# "$@" || return 255
  1481.     dir1="`dirname $1`"
  1482.     dir2="`dirname $2`"
  1483.     file1="`basename $1`"
  1484.     file2="`basename $2`"
  1485.  
  1486.     if [ ! -d $DIR_TARGET/$dir1 ]; then
  1487.         mkdir -p $DIR_TARGET/$dir1
  1488.     fi
  1489.  
  1490.     if [ ! -d $DIR_TARGET/$dir2 ]; then
  1491.         mkdir -p $DIR_TARGET/$dir2
  1492.     fi
  1493.     if [ "$dir1" = "$dir2" ]; then
  1494.         ( cd $DIR_TARGET/$dir2 ; ln -sf $file1 $file2 )
  1495.     else
  1496.         ( cd $DIR_TARGET/$dir2 ; ln -sf $1 $file2 )
  1497.     fi
  1498. }
  1499.  
  1500. # Do_Translate STRING [DICTIONARY]
  1501. #
  1502. Do_Translate()
  1503. {
  1504.   local my_lang="`get_val CONF_LST_LANG`"
  1505.   local dict=/usr/lib/LST/$my_lang/libLSTtext
  1506.  
  1507.   if [ $# -gt 1 ]; then
  1508.     dict="$2"
  1509.   fi
  1510.  
  1511.   $CMD_BOX -t --dictionary $dict --text "$1"
  1512. }
  1513.  
  1514. Get_Val()
  1515. {
  1516.     if [ $# -gt 1 ]; then
  1517.         get_val -d "$2" -f $FILE_SYSTEM_CONF "$1"
  1518.     else
  1519.         get_val -f $FILE_SYSTEM_CONF "$1"
  1520.     fi
  1521. }
  1522.  
  1523. Show_Analyse_Info()
  1524. {
  1525.     Do_Analyse_All
  1526.     Browse2 $FILE_TMP_MSG ANALYSE || return 1
  1527.     return 0
  1528. }
  1529.  
  1530.  
  1531. # libLSTconfig - configuration library shared between several scripts
  1532. #
  1533. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  1534. #
  1535.  
  1536.  
  1537. Menu_Config_CD()
  1538. {
  1539.     local cdrom=
  1540.  
  1541.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" = "SBA" ]; then
  1542.         ANSWER="`get_val CONF_CD1_DEV`"
  1543.         if [ -z "$ANSWER" ]; then
  1544.             Choose --none --other --menutitle ":CHOOSE_CD_DEV_MENUTITLE:" CD_DEV CONF_CD1_DEV || return 1
  1545.         fi
  1546.     else
  1547.         Choose --none --other --menutitle ":CHOOSE_CD_DEV_MENUTITLE:" CD_DEV CONF_CD1_DEV || return 1
  1548.     fi
  1549.     cdrom="$ANSWER"
  1550.     Do_Store CONF_CD1_DEV "$cdrom"
  1551.     if [ -n "$cdrom" ]; then
  1552.         Do_Symlink $cdrom /dev/cdrom
  1553.         Do_Load_Driver filesystem iso9660 || return 1
  1554.         Do_Load_Driver cdrom $cdrom || return 1
  1555.     fi
  1556.     ANSWER="$cdrom"
  1557.     return 0
  1558. }
  1559.  
  1560.  
  1561. Build_MOUSE()
  1562. {
  1563.     if Is_SPARC ; then
  1564.         cat << EOF
  1565. "Sun standard /dev/sunmouse"        ":TYPE_MOUSE_SUN:" \\
  1566. EOF
  1567.     else
  1568.         cat << EOF
  1569. "MouseMan mmseries serial"        ":TYPE_MOUSE_MOUSEMAN_SERIAL:" \\
  1570. "Microsoft microsoft serial"        ":TYPE_MOUSE_MICROSOFT_SERIAL:" \\
  1571. "Microsoft busmouse /dev/bmousems"    ":TYPE_MOUSE_MICROSOFT_BUS:" \\
  1572. "Logitech logitech serial"        ":TYPE_MOUSE_LOGITECH_SERIAL:" \\
  1573. "Logitech busmouse /dev/bmouselogitec"    ":TYPE_MOUSE_LOGITECH_BUS:" \\
  1574. "MouseSystems mousesystems serial"    ":TYPE_MOUSE_MOUSESYSTEMS_SERIAL:" \\
  1575. "PS2 ps/2 /dev/psaux"            ":TYPE_MOUSE_PS2_BUS:" \\
  1576. "ATI_XL busmouse /dev/bmouseatixl"    ":TYPE_MOUSE_ATI_BUS:" \\
  1577. EOF
  1578.     fi
  1579.     cat << EOF
  1580. ""                    ":TYPE_MOUSE_NONE:" \\
  1581. EOF
  1582. }
  1583.  
  1584. Menu_Config_Mouse()
  1585. {
  1586.   local type=
  1587.   local xtype=
  1588.   local dev=
  1589.   local buttons=
  1590.  
  1591.   while [ 1 ]; do
  1592.     Choose MOUSE || return 1
  1593.     if [ -z "$ANSWER" ]; then
  1594.       buttons=
  1595.       dev=
  1596.       type=
  1597.       xtype=
  1598.     else
  1599.       read type xtype dev << EOF
  1600. $ANSWER
  1601. EOF
  1602.       if [ "$dev" = "serial" ]; then
  1603.     Choose --other --menutitle ":CHOOSE_SERIAL_DEV_MENUTITLE:" SERIAL_DEV CONF_MOUSE1_DEV || continue
  1604.     dev="$ANSWER"
  1605.     if [ "$dev" = "`Get_Val CONF_MODEM1_DEV`" ]; then
  1606.       Warn ":WARN_MOUSE_MODEM_DEV_CONFLICT:" || continue
  1607.     fi
  1608.     if [ "$dev" = "`Get_Val CONF_PRINTER1_DEV`" ]; then
  1609.       Warn ":WARN_MOUSE_PRINTER_DEV_CONFLICT:" || continue
  1610.     fi
  1611.       fi    
  1612.       Do_Symlink $dev /dev/mouse
  1613.     fi
  1614.     Do_Store CONF_MOUSE1_BUTTONS "$buttons"
  1615.     Do_Store CONF_MOUSE1_DEV "$dev"
  1616.     Do_Store CONF_MOUSE1_TYPE "$type"
  1617.     Do_Store CONF_MOUSE1_X_TYPE "$xtype"
  1618.     if [ -n "$xtype" -a "$DIR_TARGET" = "/" ]; then
  1619.       Do_Setup_X
  1620.     fi
  1621.     return 0
  1622.   done
  1623. }
  1624.  
  1625. Build_PRINTER_DEV()
  1626. {
  1627.   List box PARALLEL_DEV
  1628.   List box SERIAL_DEV
  1629. }
  1630.  
  1631. Start_unconfigured_sh()
  1632. {
  1633.   local uconfsh=/etc/rc.d/unconfigured.sh
  1634.   
  1635.   echo '#!/bin/sh' > $DIR_TARGET/$uconfsh
  1636.   echo "echo -n \"Updating databases:\" " >> $DIR_TARGET/$uconfsh
  1637. }
  1638.  
  1639. Finish_unconfigured_sh()
  1640. {
  1641.     local uconfsh=/etc/rc.d/unconfigured.sh
  1642.  
  1643.     echo 'if [ -x /usr/bin/mandb ]; then ' >> $DIR_TARGET/$uconfsh
  1644.     echo "echo -n \" mandb\" " >> $DIR_TARGET/$uconfsh
  1645.     echo '/usr/bin/mandb -c > /tmp/mandb.log 2>&1 & ' >> $DIR_TARGET/$uconfsh
  1646.     echo 'fi' >> $DIR_TARGET/$uconfsh
  1647.     echo "echo" >> $DIR_TARGET/$uconfsh
  1648.     # append finish.sh downloaded from TFTP Server (auto install mode only)
  1649.     if [ -f /etc/rc.d/finish.sh ]; then
  1650.         cat /etc/rc.d/finish.sh >> $DIR_TARGET/$uconfsh
  1651.     fi
  1652.     echo "mv $uconfsh $uconfsh.done" >> $DIR_TARGET/$uconfsh
  1653.     chmod 755 $DIR_TARGET/$uconfsh
  1654. }
  1655.  
  1656. Menu_Config_Printer()
  1657. {
  1658.     local type=
  1659.     local dev=
  1660.     local speed=
  1661.     local res=
  1662.     local paper=
  1663.     local print_rm=
  1664.     local print_rp=
  1665.     local file_lpd_conf=$DIR_TARGET/etc/lpd.conf
  1666.     local print_grp_def=daemon
  1667.     local print_grp=
  1668.     local uconfsh=/etc/rc.d/unconfigured.sh
  1669.     local print_genfilter=$DIR_TARGET/usr/lib/LST/lisa/genfilter
  1670.     local print_template=$DIR_TARGET/usr/lib/LST/lisa/filter-template
  1671.     local pnum=
  1672.  
  1673.     if [ -f $file_lpd_conf ]; then
  1674.         # compiled-in value overwritten?
  1675.         print_grp="`get_val -f $file_lpd_conf group`"
  1676.         if [ -z "$print_grp" ]; then
  1677.             # compiled-in value mentionned?
  1678.             print_grp="`fgrep group= $file_lpd_conf | sed -n '1,1p' | cut -d'=' -f 2`"
  1679.         fi
  1680.     fi
  1681.     if [ -z "$print_grp" ]; then
  1682.         print_grp="$print_grp_def"
  1683.     fi
  1684.   
  1685.     while [ 1 ]; do
  1686.         # printer type
  1687.         Choose --none --other PRINTER CONF_PRINTER1_TYPE || return 1
  1688.         type="$ANSWER"
  1689.         if [ -z "$type" ]; then
  1690.             type=
  1691.             dev=
  1692.             speed=
  1693.         elif [ "$type" = "NET" ]; then
  1694.             print_rm="`Get_Val CONF_PRINTER1_HOST`"
  1695.             Ask_String PRINTER_REMOTE_HOST "$print_rm"|| return 1
  1696.             print_rm="$ANSWER"
  1697.             print_rp="`Get_Val CONF_PRINTER1_NAME`"
  1698.             if [ -z "$print_rp" -o "$MODE_QUERY" != "auto" ]; then
  1699.                 print_rp="ps"
  1700.             fi
  1701.             Ask_String PRINTER_REMOTE_DEV "$print_rp" || return 1
  1702.             print_rp="$ANSWER"
  1703.             type="NET"
  1704.         else
  1705.             # printer device
  1706.             Choose --other --menutitle ":CHOOSE_PRINTER_DEV_MENUTITLE:" PRINTER_DEV CONF_PRINTER1_DEV || return 1
  1707.             dev="$ANSWER"
  1708.             if [ -n "`echo $dev | fgrep /dev/ttyS `" ]; then
  1709.                 if [ "$dev" = "`Get_Val CONF_MOUSE1_DEV`" ]; then
  1710.                     Warn ":WARN_MOUSE_PRINTER_DEV_CONFLICT:" || continue
  1711.                 fi
  1712.                 if [ "$dev" = "`Get_Val CONF_MODEM1_DEV`" ]; then
  1713.                     Warn ":WARN_MODEM_PRINTER_DEV_CONFLICT:" || continue
  1714.                 fi
  1715.                 # printer serial portspeed
  1716.                 Choose SERIAL_SPEED CONF_PRINTER1_SPEED || continue
  1717.                 speed="$ANSWER"
  1718.             else
  1719.                 speed=
  1720.             fi
  1721.             # printer resolution
  1722.             Choose PRINTER_RES CONF_PRINTER1_RES || continue
  1723.             res="$ANSWER"
  1724.             # printer paper size
  1725.             Choose PRINTER_PAPER CONF_PRINTER1_PAPER || continue
  1726.             paper="$ANSWER"
  1727.         fi
  1728.         Do_Store CONF_PRINTER1_TYPE "$type"
  1729.         Do_Store CONF_PRINTER1_DEV "$dev"
  1730.         Do_Store CONF_PRINTER1_SPEED "$speed"
  1731.         Do_Store CONF_PRINTER1_HOST "$print_rm"
  1732.         Do_Store CONF_PRINTER1_NAME "$print_rp"
  1733.         Do_Store CONF_PRINTER1_RES "$res"
  1734.         Do_Store CONF_PRINTER1_PAPER "$paper"
  1735.  
  1736.         if [ -n "$type" ]; then
  1737.             # we have configured a printer
  1738.             # FIXME: Uaaahhh!
  1739.             # if printcap exists we disable everything with '#'
  1740.             if [ -f $DIR_TARGET/etc/printcap ]; then
  1741.                 cp -a $DIR_TARGET/etc/printcap $DIR_TARGET/etc/printcap.lisasave
  1742.                 sed '/^[^#]/s/^/#/' $DIR_TARGET/etc/printcap.lisasave \
  1743.                     > $DIR_TARGET/etc/printcap
  1744.             fi
  1745.             if [ "$type" = "NET" ]; then
  1746.                 # it is a network printer
  1747.                 # add network entry to /etc/printcap
  1748.                 cat << EOF >> $DIR_TARGET/etc/printcap
  1749. ##PRINTTOOL## REMOTE 
  1750. lp|ps:\\
  1751.         :sd=/var/spool/lpd/lp:\\
  1752.         :mx#0:\\
  1753.         :rm=$print_rm:\\
  1754.         :rp=$print_rp:
  1755. EOF
  1756.             else
  1757.                 # it is a local printer
  1758.                 if [ -n "$dev" ]; then
  1759.                     # make sure printer dev has the right settings
  1760.                     chown root.${print_grp} $DIR_TARGET/${dev}
  1761.                     chmod 660 $DIR_TARGET/${dev}
  1762.                 fi
  1763.                 # add local entry to /etc/printcap
  1764.                 cat << EOF >> $DIR_TARGET/etc/printcap
  1765. ##PRINTTOOL## LOCAL $type $res $paper {}
  1766. ps:\\
  1767.         :sd=/var/spool/lpd/ps:\\
  1768.         :mx#0:\\
  1769.         :lp=$dev:\\
  1770.         :if=/var/spool/lpd/ps/filter:\\
  1771.         :sh:
  1772. ##PRINTTOOL## LOCAL
  1773. lp:\\
  1774.     :sd=/var/spool/lpd/lp:\\
  1775.     :mx#0:\\
  1776.     :lp=$dev:\\
  1777.     :sh:
  1778. EOF
  1779.                 mkdir -p $DIR_TARGET/var/spool/lpd/ps
  1780.                 if [ ! -f $print_genfilter ]; then
  1781.                     print_genfilter=$DIR_TARGET/usr/lib/rhs/control-panel/genfilter
  1782.                     print_template=$DIR_TARGET/usr/lib/rhs/control-panel/filter-template
  1783.                 fi
  1784.                 $print_genfilter $type $res $paper \
  1785.                     < $print_template \
  1786.                     > $DIR_TARGET/var/spool/lpd/ps/filter
  1787.                 chmod 755 $DIR_TARGET/var/spool/lpd/ps/filter
  1788.             fi
  1789.  
  1790.             # FIXME: create lp devices that match in owner.group what LPRng expects
  1791.             for pnum in 0 1 2 ; do
  1792.                 rm -f $DIR_TARGET/dev/lp${pnum}
  1793.                 mknod -m 660 $DIR_TARGET/dev/lp${pnum} c 6 ${pnum}
  1794.                 chown root.${print_grp} $DIR_TARGET/dev/lp${pnum}
  1795.             done
  1796.  
  1797.             # check permissions
  1798.             if [ "$DIR_TARGET" != "/" ]; then
  1799.                 echo 'if [ -x /usr/sbin/checkpc ]; then ' >> $DIR_TARGET/$uconfsh
  1800.                 echo "echo -n \" checkpc\" " >> $DIR_TARGET/$uconfsh
  1801.                 echo '/usr/sbin/checkpc -f > /tmp/checkpc.log 2>&1 ' >> $DIR_TARGET/$uconfsh
  1802.                 # simple FIX (once only) for broken checkpc in LST 2.2
  1803.                 echo '  if [ -f /var/spool/lpd/ps/filter ]; then' >> $DIR_TARGET/$uconfsh
  1804.                 echo '    chmod +x /var/spool/lpd/ps/filter' >> $DIR_TARGET/$uconfsh
  1805.                 echo '  fi' >> $DIR_TARGET/$uconfsh
  1806.                 echo 'fi' >> $DIR_TARGET/$uconfsh
  1807.             else
  1808.                 if [ -x /usr/sbin/checkpc ]; then
  1809.                     /usr/sbin/checkpc -f > /tmp/checkpc.log 2>&1
  1810.                     /etc/rc.d/init.d/lpd restart > /dev/null 2>&1
  1811.                 fi
  1812.             fi
  1813.         fi
  1814.         return 0
  1815.     done
  1816. }
  1817.  
  1818.  
  1819. Menu_Config_Timezone()
  1820. {
  1821.     local tz_flag="`Get_Val CONF_KERNTZ_FLAG`"
  1822.     local tz_zone="`Get_Val CONF_TIMEZONE`"
  1823.  
  1824.     Choose KERNTZ $tz_flag || return 1
  1825.     Debug "KERNTZ=<$ANSWER>" 
  1826.     if [ "$ANSWER" = "KTZ_UTCTIME" ]; then
  1827.         Do_Store CONF_KERNTZ_FLAG "u"
  1828.     else
  1829.         Do_Store CONF_KERNTZ_FLAG ""
  1830.     fi
  1831.     Choose TIMEZONE $tz_zone || return 1
  1832.     Do_Store CONF_TIMEZONE "$ANSWER"
  1833.     Set_clock
  1834.     return 0
  1835. }
  1836.  
  1837. Get_Symlink()
  1838. {
  1839.   ls -l $1 | sed 's/^.* -> \(.*\)/\1/p'
  1840. }
  1841.  
  1842. Get_X_Server()
  1843. {
  1844.   if [ -f $DIR_TARGET/usr/X11R6/bin/X ]; then
  1845.     basename `Get_Symlink $DIR_TARGET/usr/X11R6/bin/X`
  1846.   fi
  1847. }
  1848.  
  1849. Do_Setup_X()
  1850. {
  1851.   local uconfsh=/etc/rc.d/unconfigured.sh
  1852.   local server="unknown"
  1853.   local label
  1854.   local tool
  1855.  
  1856.   if [ $# -gt 0 ]; then
  1857.     server="$1"
  1858.   else
  1859.     server="`Get_X_Server`"
  1860.   fi
  1861.  
  1862.   case $server in
  1863.   Xaccel)
  1864.     label=XSETUP
  1865.     tool=Xsetup
  1866.     ;;
  1867.   Xmetro)
  1868.     label=CONFIGX
  1869.     tool=configX
  1870.     ;;
  1871.   *)
  1872.     if [ -x $DIR_TARGET/usr/X11R6/bin/XF86Setup ]; then
  1873.       label=XF86SETUP
  1874.       tool=XF86Setup
  1875.     elif [ -x $DIR_TARGET/usr/X11R6/bin/xf86config ]; then
  1876.       label=XF86CONFIG
  1877.       tool=xf86config
  1878.     fi
  1879.     ;;
  1880.   esac
  1881.  
  1882.   # we strongly recommend to call any X config tool externally
  1883.   Ask_Bool CALL_${label} n || return 1
  1884.   if [ "$ANSWER" != "0" ]; then
  1885.     Msg2 NEED_CALL_${label} || return 1
  1886.     return 0
  1887.   fi
  1888.  
  1889.   if [ "$DIR_TARGET" != "/" ]; then
  1890.     # call it after we exit the initrd
  1891.     Debug "Dangerous action: Adding $tool to unconfigured.sh"
  1892.     echo "if [ -x /usr/X11R6/bin/${tool} ]; then " >> $DIR_TARGET/$uconfsh
  1893.     echo "  if [ -f /tmp/checkpoint.${tool} ]; then" >> $DIR_TARGET/$uconfsh
  1894.     echo "    echo -n \" ${tool} (skipped)\" " >> $DIR_TARGET/$uconfsh
  1895.     echo '  else' >> $DIR_TARGET/$uconfsh
  1896.     echo "    touch /tmp/checkpoint.${tool}" >> $DIR_TARGET/$uconfsh
  1897.     echo "    echo -n \" ${tool}\" " >> $DIR_TARGET/$uconfsh
  1898.     echo "    /usr/X11R6/bin/${tool}" >> $DIR_TARGET/$uconfsh
  1899.     echo "    rm -f /tmp/checkpoint.${tool}" >> $DIR_TARGET/$uconfsh
  1900.     echo '  fi' >> $DIR_TARGET/$uconfsh
  1901.     echo 'fi' >> $DIR_TARGET/$uconfsh
  1902.     Msg ":INFO_X_SETUP_DELAYED:"
  1903.   else
  1904.     Debug "Dangerous action: Calling $tool from LISA"
  1905.     sync
  1906.     /usr/X11R6/bin/${tool}
  1907.     Debug "Back in LISA: $tool returned with $?"
  1908.   fi
  1909.   return 0
  1910. }
  1911.  
  1912.  
  1913. Menu_Config_X_Server()
  1914. {
  1915.   local x_server=
  1916.  
  1917.   x_server=
  1918.   while [ 1 ]; do
  1919.     List X_SERVER | sed 's/ :.*$//' > $FILE_TMP_ANSWER
  1920.     if [ ! -s $FILE_TMP_ANSWER ]; then
  1921.       Error2 X_SERVER_NOT_INSTALLED
  1922.       Debug "NO X_Server found !?"
  1923.       return 1
  1924.     fi
  1925.     if [ -n "`sed '1d' $FILE_TMP_ANSWER`" ]; then
  1926.       Choose X_SERVER $x_server || return 1
  1927.       x_server="$ANSWER"
  1928.     else
  1929.       x_server="`cat $FILE_TMP_ANSWER`"
  1930.       Debug "taking '$x_server' from List X_SERVER"
  1931.     fi
  1932.     if [ -f /usr/X11R6/bin/$x_server ]; then
  1933.       break
  1934.     fi
  1935.     if [ -f $DIR_TARGET/usr/X11R6/bin/$x_server ]; then
  1936.       break
  1937.     fi
  1938.     Error2 X_SERVER_NOT_INSTALLED
  1939.   done
  1940.   Do_Store CONF_X_SERVER1_TYPE "$x_server"
  1941.   ( cd $DIR_TARGET/usr/X11R6/bin ; rm -f X ; ln -sf $x_server X )
  1942.   Do_Setup_X $x_server
  1943.   return 0
  1944. }
  1945.  
  1946.  
  1947. Do_Setup_locate()
  1948. {
  1949.   local uconfsh=/etc/rc.d/unconfigured.sh
  1950.  
  1951.   echo 'if [ -x /usr/bin/updatedb ]; then ' >> $DIR_TARGET/$uconfsh
  1952.   echo "echo -n \" locate\" " >> $DIR_TARGET/$uconfsh
  1953.   echo '/usr/bin/updatedb --prunepaths="/tmp /proc /mnt /var/tmp /var/spool /dev /net /auto /amd" --netuser=nobody > /dev/null 2>&1 &' >> $DIR_TARGET/$uconfsh
  1954.   echo 'fi' >> $DIR_TARGET/$uconfsh
  1955. }
  1956.  
  1957. Do_Setup_teTeX()
  1958. {
  1959.   local uconfsh=/etc/rc.d/unconfigured.sh
  1960.  
  1961.   echo 'if [ -x /usr/TeX/bin/texconfig ]; then ' >> $DIR_TARGET/$uconfsh
  1962.   echo "echo -n \" teTeX\" " >> $DIR_TARGET/$uconfsh
  1963.   echo '( cd /usr/TeX/bin ; texhash > /dev/null 2>&1 )' >> $DIR_TARGET/$uconfsh
  1964.   echo '( cd /usr/TeX/bin ; texconfig init > /dev/null 2>&1 )' >> $DIR_TARGET/$uconfsh
  1965.   echo 'fi' >> $DIR_TARGET/$uconfsh
  1966. }
  1967.  
  1968.  
  1969. # libLSTboot - boot config library shared between several scripts
  1970. #
  1971. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  1972. #
  1973.  
  1974. Do_Create_Generic_LILO_Message()
  1975. {
  1976.     rm -f $FILE_LILO_MESSAGE
  1977.     touch $FILE_LILO_MESSAGE || return 1
  1978.     chmod 400 $FILE_LILO_MESSAGE || return 1
  1979.     cat << EOF >> $FILE_LILO_MESSAGE
  1980.  
  1981.             LILO Bootloader
  1982.  
  1983.       (LST Linux generic message)
  1984.  
  1985. Press <TAB> to see possible boot choices.
  1986.  
  1987. Then enter the desired choice or press <Return>"
  1988. to boot the default (first) choice."
  1989.  
  1990. EOF
  1991.     return 0
  1992. }
  1993.  
  1994. Do_Create_Generic_LILO_Conf()
  1995. {
  1996.     local target="$1"
  1997.  
  1998.     rm -f $DIR_TARGET/$FILE_LILO_CONF.tmp
  1999.     cat << EOF > $DIR_TARGET/$FILE_LILO_CONF.tmp
  2000. #
  2001. # general section
  2002. #
  2003. EOF
  2004.     if Is_SPARC ; then
  2005.         cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2006. root = $target
  2007. partition = 1
  2008. EOF
  2009.     else
  2010.         cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2011. boot = $target
  2012. install = /boot/boot.b
  2013. EOF
  2014.     fi
  2015.     cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2016. message = $FILE_LILO_MESSAGE
  2017. prompt
  2018.  
  2019. # wait 20 seconds (200 10ths) for user to select the entry to load
  2020. timeout = 200
  2021.  
  2022. #
  2023. # default entry
  2024. #
  2025.  
  2026. EOF
  2027.     chmod 600 $DIR_TARGET/$FILE_LILO_CONF.tmp
  2028.     return 0
  2029. }
  2030.  
  2031. Check_LILO()
  2032. {
  2033.     rm -f /tmp/mbr
  2034.     if [ $# -gt 0 ]; then
  2035.         dd if=$1 bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2036.     else
  2037.         dd if=/dev/hda bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2038.         if [ ! -s /tmp/mbr ]; then
  2039.             dd if=/dev/sda bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2040.         fi
  2041.     fi
  2042.  
  2043.     if [ ! -s /tmp/mbr ]; then
  2044.         rm -f /tmp/mbr
  2045.         return 1
  2046.     else
  2047.         fgrep LILO /tmp/mbr > /dev/null
  2048.         if [ $? -eq 0 ]; then
  2049.             ANSWER="LILO"
  2050.         else
  2051.             ANSWER="unknown"
  2052.         fi
  2053.     fi
  2054.     rm -f /tmp/mbr
  2055.     return 0
  2056. }
  2057.  
  2058. Build_KERNEL_IMAGE()
  2059. {
  2060.     List_KERNEL_IMAGE $1 | do_quote
  2061. }
  2062.  
  2063. Build_LILO_ENTRY()
  2064. {
  2065.     Build_KERNEL_IMAGE $1
  2066.     Build_Other_OS
  2067. }
  2068.  
  2069. List_KERNEL_IMAGE()
  2070. {
  2071.   local prefix="$1"
  2072.   local prefixed_image
  2073.   local image
  2074.  
  2075.   for prefixed_image in $prefix/vmlinuz* $prefix/boot/vmlinuz* ; do
  2076.     if [ -f $prefixed_image ]; then
  2077.       image="`echo $prefixed_image | sed "s:^$prefix::"`"
  2078.       echo "$image (Linux Kernel Image)"
  2079.     fi
  2080.   done
  2081. }
  2082.  
  2083. Build_Other_OS()
  2084. {
  2085.     local i=
  2086.  
  2087.     # check for Linux partitions with LILO
  2088.     for i in `sysinfo --tag -C Linux --partition` ; do
  2089.         Check_LILO $i
  2090.         if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  2091.             sysinfo --postlabel " (LILO)" --box -P $i --partition
  2092.         fi
  2093.     done
  2094.     sysinfo --postlabel " (DOS or OS/2)" --box -C DOSC --partition
  2095.     sysinfo --postlabel " (OS/2)" --box -C Bootmanager --partition
  2096.     sysinfo --postlabel " (BSD)" --box -C BSD --partition
  2097.     sysinfo --postlabel " (Solaris?)" --box -C Solaris --partition
  2098. }
  2099.  
  2100. Build_LILO_ADD_ENTRY()
  2101. {
  2102.     cat << EOF
  2103. "END" ":TYPE_LILO_ADD_ENTRY_NONE:" \\
  2104. EOF
  2105.     Build_KERNEL_IMAGE $1
  2106.     Build_Other_OS
  2107. }
  2108.  
  2109. Build_LILO_MODE()
  2110. {
  2111.     local boot_mode=
  2112.  
  2113.     Is_Expert
  2114.     if [ $? -eq 0 ]; then
  2115.         # echo "\"FLOPPY\" \":TYPE_LILO_MODE_FLOPPY:\" \\"
  2116.         echo "\"LILOACTIVE\" \":TYPE_LILO_MODE_ACTIVE:\" \\"
  2117.         echo "\"LILOPASSIVE\" \":TYPE_LILO_MODE_PASSIVE:\" \\"
  2118.     else
  2119.         echo "\"LILOACTIVE\" \":TYPE_LILO_MODE_ACTIVE:\" \\"
  2120.         echo "\"ROOT\" \":TYPE_LILO_MODE_PASSIVE:\" \\"
  2121.     fi
  2122.     echo "\"MBR\" \":TYPE_LILO_MODE_MBR:\" \\"
  2123.     echo "\"NONE\" \":TYPE_LILO_MODE_NONE:\" \\"
  2124. }
  2125.  
  2126. Build_LILO_TARGET()
  2127. {
  2128.     local root_part="$1"
  2129.     local protect_root=
  2130.  
  2131.     if [ $# -gt 1 -a "$2" = "msdos" ]; then
  2132.         protect_root=true
  2133.     fi
  2134.  
  2135.     if [ -n "`sysinfo --tag --disk | fgrep -x /dev/hda`" ]; then
  2136.         echo "\"/dev/hda\" \":TYPE_LILO_TARGET_MBR_IDE:\" \\"
  2137.     fi
  2138.     if [ -n "`sysinfo --tag --disk | fgrep -x /dev/sda`" ]; then
  2139.         echo "\"/dev/sda\" \":TYPE_LILO_TARGET_MBR_SCSI:\" \\"
  2140.     fi
  2141.     if [ -n "`sysinfo --tag --disk | fgrep -x /dev/rd/c0d0`" ]; then
  2142.         echo "\"/dev/rd/c0d0\" \":TYPE_LILO_TARGET_MBR_SCSI: (/dev/rd/c0d0)\" \\"
  2143.     fi
  2144.     if [ -n "`sysinfo --tag --disk | fgrep -x /dev/ida/c0d0`" ]; then
  2145.         echo "\"/dev/ida/c0d0\" \":TYPE_LILO_TARGET_MBR_SCSI: (/dev/ida/c0d0)\" \\"
  2146.     fi
  2147.     if [ -z "$protect_root" ]; then
  2148.         echo "\"$root_part\" \":TYPE_LILO_TARGET_ROOT: ($root_part)\" \\"
  2149.     fi
  2150.     if [ -n "`sysinfo --expert --tag -C LILOPASSIVE --partition | fgrep -v $root_part`" ]; then
  2151.         echo "\"OTHER\" \":TYPE_LILO_TARGET_OTHER:\" \\"
  2152.     fi
  2153.         echo "\"/dev/fd0\" \":TYPE_LILO_TARGET_FLOPPY:\" \\"
  2154.     echo "\"NONE\" \":TYPE_LILO_TARGET_NONE:\" \\"
  2155.  
  2156.     return 0
  2157. }
  2158.  
  2159. Build_LILO_TARGET_OTHER()
  2160. {
  2161.     local root_part="$1"
  2162.  
  2163.     sysinfo --box --partition -C LILOPASSIVE | fgrep -v "\"$root_part\""
  2164.     # expert users may like to install LILO in extended partitions
  2165.     sysinfo --box --partition -C extended
  2166. }
  2167.  
  2168. Do_Analyse_Boot_Setup()
  2169. {
  2170.     local mbr=
  2171.     local dummy=
  2172.     local bios_boot=
  2173.     local active_partitions=
  2174.     local os2_bootmgr=
  2175.     local lilo_in_mbr=
  2176.  
  2177.     echo "======================================================================"
  2178.     echo "                         LISA boot analysis"
  2179.     echo "======================================================================"
  2180.     echo
  2181.  
  2182.     # check if there is a LILO in the MBR
  2183.     echo "Analysis of Master Boot Record (MBR)"
  2184.     echo "------------------------------------"
  2185.     mbr="`sysinfo --tag -C MBR --disk`"
  2186.     Check_LILO $mbr
  2187.     if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  2188.         lilo_in_mbr=true
  2189.         cat << EOF
  2190. MBR already contains a LILO Boot Manager
  2191. This LILO can be replaced now by another LILO, left alone, or (for DOS
  2192. systems) replaced by DOS's default MBR by using the DOS 'FDISK /MBR'
  2193. command
  2194. EOF
  2195.     else
  2196.         echo "No LILO found in the MBR."
  2197.     fi
  2198.     echo
  2199.  
  2200.     # first look for active partitions
  2201.     active_partitions="`sysinfo --tag -C active --partition`"
  2202.     echo "Active partition analysis"
  2203.     echo "-------------------------"
  2204.     if [ -z "$active_partitions" ]; then
  2205.         echo "No active partitions found!"
  2206.     else
  2207.         sysinfo --label -C active --partition
  2208.     fi
  2209.  
  2210.     echo
  2211.     echo "Conclusion"
  2212.     echo "----------"
  2213.  
  2214.     if [ -n "$lilo_in_mbr" ]; then
  2215.         echo "===> The BIOS will boot from the master boot record $mbr."
  2216.         echo
  2217.         return 0
  2218.     fi
  2219.     # the BIOS will boot from the first active partition
  2220.     bios_boot="`sysinfo --tag -C active --partition | sed -n '1p'`"
  2221.     if [ -z "$bios_boot" ]; then
  2222.         echo "===> it seems you have no valid boot setup!"
  2223.         echo "===> you have 2 choices to fix that:"
  2224.         echo "A.) install a boot loader/manager in the master boot record"
  2225.         echo "    of your first hard disk."
  2226.         echo "B.) install a boot loader/manager in a primary partition on"
  2227.         echo "    the first hard disk and activate this partition."
  2228.         echo
  2229.         return 1
  2230.     fi
  2231.     echo "===> The BIOS will boot the first active partition $bios_boot."
  2232.     Check_LILO $bios_boot
  2233.     if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  2234.         echo "===> $bios_boot seems to contain a LILO boot manager."
  2235.     else
  2236.         # check for DOSC
  2237.         if [ "$bios_boot" = "`sysinfo --tag -C DOSC --partition`" ]; then
  2238.             echo "===> $bios_boot seems to contain a DOS boot loader."
  2239.         # check for OS/2 Bootmanager
  2240.         elif [ "$bios_boot" = "`sysinfo --tag -C Bootmanager --partition | fgrep -x $bios_boot`" ]; then
  2241.             echo "===> $bios_boot seems to contain a OS/2 boot manager."
  2242.         # check for BSD Bootmanager
  2243.         elif [ "$bios_boot" = "`sysinfo --tag -C BSD --partition | fgrep -x $bios_boot`" ]; then
  2244.             echo "===> $bios_boot seems to contain a BSD boot manager."
  2245.         # check for Solaris Bootmanager
  2246.         elif [ "$bios_boot" = "`sysinfo --tag -C Solaris --partition | fgrep -x $bios_boot`" ]; then
  2247.             echo "===> $bios_boot seems to contain a Solaris boot manager."
  2248.         else
  2249.             echo "===> $bios_boot seems to contain no (or an unknown) boot manager."
  2250.         fi
  2251.     fi
  2252.     echo
  2253.     return 0
  2254. }
  2255.  
  2256. Do_Activate_Partition()
  2257. {
  2258.     local dummy=
  2259.     local hd_dev=
  2260.     local hd_part=
  2261.     local f_name=Do_Activate_Partition
  2262.     local f_args=1 # (partition) ->
  2263.  
  2264.     Check_Args $f_name $f_args $# "$@" || return 255
  2265.  
  2266.     hd_dev=`echo "$1" | cut -c 1-8`
  2267.     if [ "$hd_dev" = "/dev/rd/" ]; then
  2268.         hd_dev=`echo "$1" | cut -c 1-12`
  2269.         hd_part=`echo "$1" | cut -c 14-`
  2270.     elif [ "$hd_dev" = "/dev/ida" ]; then
  2271.         hd_dev=`echo "$1" | cut -c 1-13`
  2272.         hd_part=`echo "$1" | cut -c 15-`
  2273.     else
  2274.         hd_part=`echo "$1" | cut -c 9-`
  2275.     fi
  2276.     dummy="$hd_dev $hd_part"
  2277.     #Info ":INFO_ACTIVATING_PARTITION:"
  2278.     activate $dummy 2> $FILE_TMP_ERR
  2279.     if [ $? -eq 0 ]; then
  2280.         Msg ":INFO_ACTIVATE_SUCCESS:"
  2281.     else
  2282.         Error --file $FILE_TMP_ERR "$1 ; :ERR_ACTIVATE_PROBLEMS:"
  2283.         return 1
  2284.     fi
  2285.     return 0
  2286. }
  2287.  
  2288. Do_Install_LILO()
  2289. {
  2290.     local lilo_cmd
  2291.  
  2292.     if Is_SPARC ; then
  2293.         lilo_cmd=silo
  2294.     else
  2295.         lilo_cmd=lilo
  2296.     fi
  2297.  
  2298.     Info ":INFO_LILO_RUNNING:"
  2299.     if [ "$DIR_TARGET" != "/" ]; then
  2300.         ( cd $DIR_TARGET; chroot $DIR_TARGET sbin/$lilo_cmd && echo "LILO ok" ) > $DIR_TARGET/tmp/lilo.error 2>&1
  2301.         mv $DIR_TARGET/tmp/lilo.error $FILE_TMP_ERR
  2302.         # $lilo_cmd -r $DIR_TARGET > $FILE_TMP_ERR 2>&1
  2303.     else
  2304.         ( /sbin/$lilo_cmd && echo "LILO ok" ) > $FILE_TMP_ERR 2>&1
  2305.     fi
  2306.     if [ -z "`fgrep -x 'LILO ok' $FILE_TMP_ERR`" ]; then
  2307.         Error --file $FILE_TMP_ERR ":ERR_LILO_PROBLEMS:"
  2308.         return 1
  2309.     else
  2310.         $CMD_BOX --nobutton --msg ":INFO_LILO_SUCCESS:"
  2311.     fi
  2312.     return 0
  2313. }
  2314.  
  2315. Do_Add_LILO_Table()
  2316. {
  2317.   local table=
  2318.   local partnum=
  2319.  
  2320.   table="`echo $1 | cut -c 1-8`"
  2321.   if [ -n "$table" ]; then
  2322.     partnum="`echo $1 | cut -c 9-`"
  2323.     if [ $partnum -lt 5 ]; then
  2324.       echo "    table = $table" >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2325.     fi
  2326.     if ! Is_SPARC ; then
  2327.       echo "    loader = /boot/chain.b" >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2328.     fi
  2329.   fi
  2330. }
  2331.  
  2332. Ask_LILO_Label()
  2333. {
  2334.     local label=
  2335.     local partid=
  2336.  
  2337.     echo "$1" | fgrep '/dev/' > /dev/null
  2338.     if [ $? -eq 0 ]; then
  2339.         label="`echo $1 | cut -c 6-`"
  2340.         partid="`Get_Partition_Info --id $1`"
  2341.         case $partid in
  2342.         1|4|6|11|12|14)
  2343.             label="dos"
  2344.             ;;
  2345.         10)
  2346.             label="os2"
  2347.             ;;
  2348.         130)
  2349.             label="solaris"
  2350.             ;;
  2351.         131)
  2352.             label="lilo-$label"
  2353.             ;;
  2354.         165)
  2355.             label="bsd"
  2356.             ;;
  2357.         169)
  2358.             label="NetBSD"
  2359.             ;;
  2360.         esac
  2361.     else
  2362.         # propose "linux" as label if it looks like our kernel
  2363.         if [ -n "`echo $1 | sed -n '/^\/boot\/vmlinuz/p'`" ]; then
  2364.             label="linux"
  2365.         elif [ "$1" = "/vmlinuz" ]; then
  2366.             label="linux"
  2367.         fi
  2368.     fi
  2369.     sed -n '/label[ ]*=/s/^.*label[ ]*=[ ]*\(.*\)$/\1/p' $DIR_TARGET/$FILE_LILO_CONF.tmp | fgrep -x $label > /dev/null
  2370.     if [ $? -eq 0 ]; then
  2371.         label=
  2372.     fi
  2373.  
  2374.     while [ 1 ]; do
  2375.         Ask_String LILO_LABEL "$label" || return 1
  2376.         if [ -z "$ANSWER" ]; then
  2377.             continue
  2378.         fi
  2379.         label="$ANSWER"
  2380.         # CHECK: test whether label already exists
  2381.         sed -n '/label[ ]*=/s/^.*label[ ]*=[ ]*\(.*\)$/\1/p' $DIR_TARGET/$FILE_LILO_CONF.tmp | fgrep -x $label > /dev/null
  2382.         if [ $? -eq 0 ]; then
  2383.             Warn ":WARN_LABEL_ALREADY_USED:"
  2384.             continue
  2385.         else
  2386.             cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2387.     label = $label
  2388. EOF
  2389.             return 0
  2390.         fi
  2391.     done
  2392. }
  2393.  
  2394. Ask_LILO_Params()
  2395. {
  2396.   local append="$1"
  2397.  
  2398.   Debug "append = <$append>"
  2399.   # remove quotes from any previous append string
  2400.   append="`echo $append | cut -d'\"' -f 2`"
  2401.   Debug "append = <$append>"
  2402.   Ask_String LILO_PARAMS "$append" || return 1
  2403.   if [ -n "$ANSWER" ]; then
  2404.     echo "    append = \"$ANSWER\"" >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2405.   fi
  2406.   return 0
  2407. }
  2408.  
  2409. Ask_LILO_Initrd()
  2410. {
  2411.   local initrd_file=/boot/initrd.gz
  2412.  
  2413.   if [ ! -f $DIR_TARGET/$initrd_file ]; then
  2414.     initrd_file=
  2415.     ANSWER=
  2416.     return 0
  2417.   fi
  2418.  
  2419.   Ask_String LILO_INITRD "$initrd_file" || return 1
  2420.   return 0
  2421. }
  2422.  
  2423. Ask_LILO_Entry()
  2424. {
  2425.   local build_function="$1"
  2426.   local text_label="$2"
  2427.   local root_part="$3"
  2428.   local image=
  2429.   local entry=image
  2430.   local label=
  2431.   local use_initrd=
  2432.   local append=
  2433.  
  2434.   Choose --build "$build_function $DIR_TARGET" $text_label || return 1
  2435.   if [ "$ANSWER" = "END" ]; then
  2436.     return 0
  2437.   fi
  2438.   image="$ANSWER"
  2439.   echo "$image" | fgrep '/dev/' > /dev/null
  2440.   if [ $? -eq 0 ]; then
  2441.     entry=other
  2442.     cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2443.  
  2444. $entry = $image
  2445. EOF
  2446.     Ask_LILO_Label $image || continue
  2447.     Do_Add_LILO_Table $image
  2448.   else
  2449.     entry=image
  2450.     cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2451.  
  2452. $entry = $image
  2453. EOF
  2454.     Ask_LILO_Initrd || continue
  2455.     if [ -n "$ANSWER" ]; then
  2456.       echo "    initrd = \"$ANSWER\"" >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2457.       use_initrd=true
  2458.       append="load_ramdisk=1 ramdisk_size=2880"
  2459.     else
  2460.       append=""
  2461.     fi
  2462.     Ask_LILO_Label $image || continue
  2463.     cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2464.     root = $root_part
  2465.     read-only
  2466. EOF
  2467.     Ask_LILO_Params "$append"
  2468.   fi
  2469.   return 0
  2470. }
  2471.  
  2472. Menu_Config_LILO_HD()
  2473. {
  2474.     local default_mbr=
  2475.     local default_target=
  2476.     local lilo_in_mbr=
  2477.     local mode=
  2478.     local os2_bootmgr=
  2479.     local root_part=
  2480.     local root_part_id=
  2481.     local root_part_type=
  2482.     local target=
  2483.  
  2484.     Do_Analyse_Boot_Setup > $DIR_LST_TMP/bootsetup
  2485.     Browse2 $DIR_LST_TMP/bootsetup ANALYSE_BOOT_SETUP || return 1
  2486.  
  2487.     # -- outermost loop start --
  2488.     while [ 1 ]; do
  2489.  
  2490.         # -- target loop start -- (not indended)
  2491.         while [ 1 ]; do
  2492.     # get first mbr
  2493.     default_mbr="`sysinfo --tag -C MBR --disk`"
  2494.     Debug "default_mbr = <$default_mbr>"
  2495.  
  2496.     # get root partition
  2497.     if [ "$DIR_TARGET" != "/" ]; then
  2498.         root_part="$CONF_INSTALL_ROOT"
  2499.     else
  2500.         root_part="`rdev | cut -d' ' -f 1`"
  2501.     fi
  2502.     Debug "root_part = <$root_part>"
  2503.  
  2504.     # get root partition type
  2505.     root_part_id="`Get_Partition_Info --id $root_part`"
  2506.     Debug "root_part_id = <$root_part_id>"
  2507.     case $partid in
  2508.     1|4|6|11|12|14)
  2509.         root_part_type=msdos
  2510.         ;;
  2511.     131)    
  2512.         root_part_type=ext2
  2513.         ;;
  2514.     esac
  2515.     Debug "root_part_type = <$root_part_type>"
  2516.  
  2517.     # check MBR for LILO
  2518.     Check_LILO
  2519.     if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  2520.         lilo_in_mbr=true
  2521.         Debug "detected LILO in $default_mbr"
  2522.     fi
  2523.  
  2524.     # check for OS/2 boot manager
  2525.     os2_bootmgr="`sysinfo --tag -C Bootmanager --partition | sed -n '1p'`"
  2526.     if [ -n "$os2_bootmgr" ]; then
  2527.         Debug "detected OS/2 Bootmanager in $os2_bootmgr"
  2528.     fi
  2529.  
  2530.     # try to offer a smart default target
  2531.     default_target="`Get_Val CONF_INSTALL_LILO`"
  2532.     if [ -z "$default_target" ]; then
  2533.         if [ -n "$lilo_in_mbr" ]; then
  2534.             # bad idea to use the MBR, but if they are used to it...
  2535.             default_target="$default_mbr"
  2536.         else
  2537.             # use root partition per default
  2538.             default_target="$root_part"
  2539.             # use other partition if root is MSDOS
  2540.             if [ "$root_part_type" = "msdos" ]; then
  2541.                 default_target=OTHER
  2542.                 # do not allow LILO on msdos partitions
  2543.                 Msg ":INFO_NO_LILO_ON_UMSDOS:"
  2544.             else
  2545.                 # check if root_part is a primary partition on 1st disk
  2546.                 if [ -z "`sysinfo --tag -C LILOACTIVE --partition | fgrep -x $root_part`" ]; then
  2547.                     # without OS/2 bootmanager use the MBR
  2548.                     if [ -z "$os2_bootmgr" ]; then
  2549.                         default_target="$default_mbr"
  2550.                     fi
  2551.                 fi
  2552.             fi
  2553.         fi
  2554.     fi
  2555.     Debug "default_target = <$default_target>"
  2556.  
  2557.     Choose --build "Build_LILO_TARGET $root_part $root_part_type" LILO_TARGET $default_target || return 1
  2558.     target="$ANSWER"
  2559.  
  2560.     case $target in
  2561.     /dev/hda|/dev/sda)
  2562.         mode=MBR
  2563.         ;;
  2564.     $root_part)
  2565.         mode=ROOT
  2566.         ;;
  2567.     OTHER)
  2568.         mode=OTHER
  2569.         Choose --build "Build_LILO_TARGET_OTHER $root_part" LILO_TARGET_OTHER || continue
  2570.         target="$ANSWER"
  2571.         ;;
  2572.     /dev/fd0H1440|/dev/fd0)
  2573.         mode=FLOPPY
  2574.         ;;
  2575.     NONE)
  2576.         return 0
  2577.         ;;
  2578.     esac
  2579.  
  2580.     # BEGIN: sanity checks
  2581.  
  2582.     if [ "$mode" = "MBR" -o "$mode" = "FLOPPY" ]; then
  2583.         break
  2584.     fi
  2585.  
  2586.     # warn if a LILO is detected in the MBR
  2587.     if [ -n "$lilo_in_mbr" ]; then
  2588.         Warn ":WARN_LILO_FOUND_IN_MBR:" || continue
  2589.     fi
  2590.     break
  2591.  
  2592.     # END: sanity checks
  2593.  
  2594.         # -- target loop end --
  2595.         done
  2596.  
  2597.         # -- default entry loop start --
  2598.         while [ 1 ]; do
  2599.             again=true
  2600.             Do_Create_Generic_LILO_Conf $target
  2601.             Ask_LILO_Entry Build_LILO_ENTRY LILO_DEFAULT_ENTRY $root_part || break
  2602.  
  2603.             again=
  2604.             break
  2605.         # -- default loop end --
  2606.         done
  2607.         if [ -n "$again" ]; then
  2608.             continue
  2609.         fi
  2610.         cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2611.  
  2612. #
  2613. # additional entries
  2614. #
  2615.  
  2616. EOF
  2617.  
  2618.         # -- alternate loop start --
  2619.         while [ 1 ]; do
  2620.             again=true
  2621.             Ask_LILO_Entry Build_LILO_ADD_ENTRY LILO_ADD_ENTRY $root_part || break
  2622.             if [ "$ANSWER" = "END" ]; then
  2623.                 again=
  2624.                 break
  2625.             fi
  2626.         # -- alternate loop end --
  2627.         done
  2628.         if [ -n "$again" ]; then
  2629.             continue
  2630.         fi
  2631.  
  2632.         Browse2 $DIR_TARGET/$FILE_LILO_CONF.tmp LILO_CONF || continue
  2633.         Ask_Bool INSTALL_LILO || continue
  2634.         if [ "$ANSWER" != "0" ]; then
  2635.             continue
  2636.         fi
  2637.         cp -a $DIR_TARGET/$FILE_LILO_CONF.tmp $DIR_TARGET/$FILE_LILO_CONF || continue
  2638.         if Is_SPARC ; then
  2639.             cp -a $DIR_TARGET/$FILE_LILO_CONF $DIR_TARGET/etc/silo.conf
  2640.         fi
  2641.  
  2642.         Do_Install_LILO || continue
  2643.  
  2644.         if [ "$mode" = "MBR" -o "$mode" = "FLOPPY" ]; then
  2645.             break
  2646.         fi
  2647.  
  2648.         # warn if target is no primary on 1st disk and no OS/2 Bootmanager
  2649.         if [ -z "`sysinfo --tag -C LILOACTIVE --partition | fgrep -x $target`" -a -z "$os2_bootmgr" ]; then
  2650.             Warn ":WARN_LILO_NOT_ACTIVE_AND_NO_BOOTMANAGER:" || continue
  2651.         else
  2652.             if [ -z "`sysinfo --tag -C active --partition | fgrep -x $target`" ]; then
  2653.                 Ask_Bool --pretext "$target ; " ACTIVATE_PARTITION || continue
  2654.                 if [ "$ANSWER" = "0" ]; then
  2655.                     Do_Activate_Partition $target || continue
  2656.                 else
  2657.                     Warn ":WARN_LILO_NOT_ACTIVE:" || continue
  2658.                 fi
  2659.             fi
  2660.         fi
  2661.         break
  2662.     done
  2663.     # -- outermost loop end --
  2664.     Do_Store CONF_INSTALL_LILO "$target"
  2665.     return 0
  2666. }
  2667.  
  2668.  
  2669. # libLSTbox - box call library shared between several scripts
  2670. #
  2671. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  2672. #
  2673.  
  2674. # Ask what goal build_function
  2675. Ask()
  2676. {
  2677.     FUNC_NAME=Ask
  2678.     local cmd=$FILE_TMP_COMMAND
  2679.     local what="$1"
  2680.     local goal="$2"
  2681.     local ans=/tmp/LST/ans
  2682.     local prefix=
  2683.     local defval=
  2684.  
  2685.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  2686.  
  2687.     shift 2
  2688.  
  2689.     if [ "X$1" = "X--default" ]; then
  2690.         defval="$2"
  2691.         shift 2
  2692.     fi
  2693.  
  2694.     case $what in
  2695.     bool|string)
  2696.         prefix=ASK
  2697.         defval="$1"
  2698.         ;;
  2699.     one)
  2700.         prefix=CHOOSE
  2701.         ;;
  2702.     menu)
  2703.         prefix=MENU
  2704.         what=one
  2705.         ;;
  2706.     esac
  2707.  
  2708.     cat << EOF > $cmd
  2709. #!/bin/sh
  2710.  
  2711. $CMD_BOX --title ":${prefix}_${goal}_TITLE:" \\
  2712.     --help ":${prefix}_${goal}_HELP:" \\
  2713.     --default "${defval}" \\
  2714.     --${what} ":${prefix}_${goal}_TEXT:" \\
  2715. EOF
  2716.  
  2717.     case $what in
  2718.     one)
  2719.         $@ >> $cmd
  2720.         ;;
  2721.     esac
  2722.  
  2723.     echo "2> $ans" >> $cmd
  2724.     chmod 755 $cmd
  2725.  
  2726.     # log command if requested
  2727.     Log_Cmd
  2728.  
  2729.     $cmd || return 1
  2730.     export ANSWER="`cat $ans`"
  2731.     return 0
  2732. }
  2733.  
  2734. #
  2735. # libLSTnew
  2736. #
  2737.  
  2738. # Ask what goal build_function
  2739. Ask2()
  2740. {
  2741.     FUNC_NAME=Ask
  2742.     local cmd=$FILE_TMP_COMMAND
  2743.     local what="$1"
  2744.     local goal="$2"
  2745.     local ans=$FILE_TMP_ANSWER
  2746.     local prefix=
  2747.     local defval=
  2748.     local other=
  2749.     local pretext=
  2750.     local posttext=
  2751.  
  2752.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  2753.  
  2754.     shift 2
  2755.  
  2756.     while [ 1 ]; do
  2757.         if [ $# -eq 0 ]; then
  2758.             break
  2759.         fi
  2760.         if [ "X$1" = "X--other" ]; then
  2761.             other=true
  2762.             shift 1
  2763.         elif [ "X$1" = "X--default" ]; then
  2764.             defval="$2"
  2765.             shift 2
  2766.         elif [ "X$1" = "X--pretext" ]; then
  2767.             pretext="$2"
  2768.             shift 2
  2769.         elif [ "X$1" = "X--posttext" ]; then
  2770.             posttext="$2"
  2771.             shift 2
  2772.         else
  2773.             break
  2774.         fi
  2775.     done
  2776.  
  2777.     case $what in
  2778.     bool|string)
  2779.         prefix=ASK
  2780.         if [ -z "$defval" ]; then
  2781.             defval="$1"
  2782.         fi
  2783.         ;;
  2784.     one)
  2785.         prefix=CHOOSE
  2786.         ;;
  2787.     menu)
  2788.         prefix=MENU
  2789.         what=one
  2790.         ;;
  2791.     esac
  2792.  
  2793.     if [ "$what" = "one" ]; then
  2794.         rm -f ${cmd}.itm
  2795.         $@ > ${cmd}.itm
  2796.         if [ ! -s ${cmd}.itm ]; then
  2797.             Debug "Error: empty list: $@"
  2798.             what=string
  2799.             prefix=ASK
  2800.         fi
  2801.     fi
  2802.  
  2803.     cat << EOF > $cmd
  2804. #!/bin/sh
  2805.  
  2806. $CMD_BOX --title ":${prefix}_${goal}_TITLE:" \\
  2807.     --help ":${prefix}_${goal}_HELP:" \\
  2808.     --default "${defval}" \\
  2809.     --${what} "${pretext}:${prefix}_${goal}_TEXT:${posttext}" \\
  2810. EOF
  2811.  
  2812.     if [ "$what" = "one" ]; then
  2813.         if [ "$other" = "true"  ]; then
  2814.             echo "\"OTHER\" \":${prefix}_${goal}_OTHER:\" \\" >> ${cmd}
  2815.         fi
  2816.         if [ "$none" = "true"  ]; then
  2817.             echo "\"NONE\" \":${prefix}_${goal}_NONE:\" \\" >> ${cmd}
  2818.         fi
  2819.         cat ${cmd}.itm >> ${cmd}
  2820.     fi
  2821.  
  2822.     echo "2> $ans" >> $cmd
  2823.     chmod 755 $cmd
  2824.  
  2825.     # log command if requested
  2826.     Log_Cmd
  2827.  
  2828.     $cmd || return 1
  2829.     export ANSWER="`cat $ans`"
  2830.     return 0
  2831. }
  2832.  
  2833.  
  2834. Get_Module_Line()
  2835. {
  2836.     sed -n "/^%[^%]*%$2%/p" $1
  2837. }
  2838.  
  2839. Get_Module_Param_Num()
  2840. {
  2841.     Get_Module_Line $1 $2 | cut -d'%' -f $NUM_POS
  2842. }
  2843.  
  2844. List_Param_Of_Module()
  2845. {
  2846.     local num
  2847.     local i=0
  2848.     local pos="`do_calc $NUM_POS + 1`"
  2849.  
  2850.     num="`Get_Module_Param_Num $1 $2`"
  2851.     if [ -z "$num" -o "$num" = '?' ]; then
  2852.         num=unknown
  2853.         Debug 'Number of insmod parameters is unknown !'
  2854.         return 1
  2855.     elif [ "$num" = "0" ]; then
  2856.         num=none
  2857.         Debug "No insmod params."
  2858.         return 0
  2859.     fi
  2860.  
  2861.     while [ 1 ]; do
  2862.         i="`do_calc $i + 1`"
  2863.         if [ $i -gt $num ]; then
  2864.             break
  2865.         fi
  2866.         parm="`Get_Module_Line $1 $2 | cut -d'%' -f $pos`"
  2867.         echo "$parm"
  2868.         pos="`do_calc $pos + $NUM_PER_PARAM`"
  2869.     done
  2870. }
  2871.  
  2872. Build_Param_Of_Module()
  2873. {
  2874.     local params
  2875.     local val
  2876.     local i
  2877.  
  2878.     params="`List_Param_Of_Module $1 $2`"
  2879.     if [ $? -ne 0 ]; then
  2880.         return 1
  2881.     fi
  2882.     if [ -z "$params" ]; then
  2883.         return 0
  2884.     fi
  2885.     echo "\"DONE\" \":CHOOSE_PARAM_OF_MODULE_DONE:\" \\"
  2886.     echo "\"OTHER\" \":CHOOSE_PARAM_OF_MODULE_OTHER:\" \\"
  2887.     for i in $params ; do
  2888.         val="`get_val -f $FILE_VALUES_SEL Value_Of_Param%${2}%${i}%current`"
  2889.         echo "\"$i\" \"$i [${val}]\" \\"
  2890.     done
  2891. }
  2892.  
  2893. Build_Value_Of_Param()
  2894. {
  2895.     local num
  2896.     local i=0
  2897.     local pos="`do_calc $NUM_POS + 1`"
  2898.     local posvals
  2899.     local posdef
  2900.     local values
  2901.     local defval
  2902.     local val
  2903.  
  2904.     num="`Get_Module_Param_Num $1 $2`"
  2905.     if [ -z "$num" -o "$num" = '?' ]; then
  2906.         num=unknown
  2907.         Debug 'Number of insmod parameters is unknown !'
  2908.         return 1
  2909.     elif [ "$num" = "0" ]; then
  2910.         num=none
  2911.         Debug "No insmod params."
  2912.         return 0
  2913.     fi
  2914.     Debug "num = $num"
  2915.  
  2916.     while [ 1 ]; do
  2917.         i="`do_calc $i + 1`"
  2918.         if [ $i -gt $num ]; then
  2919.             Debug "param $3 not found."
  2920.             break
  2921.         fi
  2922.         parm="`Get_Module_Line $1 $2 | cut -d'%' -f $pos`"
  2923.         if [ "$parm" != "$3" ]; then
  2924.             pos="`do_calc $pos + $NUM_PER_PARAM`"
  2925.             continue
  2926.         fi
  2927.         posvals="`do_calc $pos + 2`"
  2928.         Debug "posvals = <$posvals>"
  2929.         posdef="`do_calc $pos + 3`"
  2930.         Debug "posdef = <$posdef>"
  2931.         values="`Get_Module_Line $1 $2 | cut -d'%' -f $posvals | sed 's/,/ /g'`"
  2932.         Debug "values = <$values>"
  2933.         defval="`Get_Module_Line $1 $2 | cut -d'%' -f $posdef`"
  2934.         Debug "defval = <$defval>"
  2935.         for val in $values ; do
  2936.             if [ "X$val" = "X$defval" ]; then
  2937.                 echo "\"$val\" \"$val [default]\" \\"
  2938.             else
  2939.                 echo "\"$val\" \"$val\" \\"
  2940.             fi
  2941.         done
  2942.         break
  2943.     done
  2944. }
  2945.  
  2946. Choose_Param_Of_Module()
  2947. {
  2948.     local modname="$1"
  2949.     local modparam
  2950.  
  2951.     shift 1
  2952.     if [ $# -gt 0 ]; then
  2953.         modparam="$1"
  2954.     else
  2955.         modparam="`get_val -f $FILE_VALUES_SEL Param_Of_Module%${modname}%current`"
  2956.     fi
  2957.     Ask2 one PARAM_OF_MODULE --pretext "module=$modname ; ; " --default "$modparam" Build_Param_Of_Module $FILE_MODULES_DATA $modname || return 1
  2958.     modparam="$ANSWER"
  2959.     set_val -f $FILE_VALUES_SEL Param_Of_Module%${modname}%current "${modparam}"
  2960.     return 0
  2961. }
  2962.  
  2963.  
  2964. Choose_Value_Of_Param()
  2965. {
  2966.     local modname="$1"
  2967.     local modparam="$2"
  2968.     local paramval
  2969.  
  2970.     shift 2
  2971.     if [ $# -gt 0 ]; then
  2972.         paramval="$1"
  2973.     else
  2974.         paramval="`get_val -f $FILE_VALUES_SEL Value_Of_Param%${modname}%${modparam}%current`"
  2975.     fi
  2976.     Ask2 one VALUE_OF_PARAM --other --pretext "module=$modname ; parameter=$modparam ; ; " --default "$paramval" Build_Value_Of_Param $FILE_MODULES_DATA $modname $modparam || return 1
  2977.     paramval="$ANSWER"
  2978.     if [ "$paramval" = "OTHER" ]; then
  2979.         paramval="`get_val -f $FILE_VALUES_SEL Value_Of_Param%${modname}%${modparam}%current`"
  2980.         Ask2 string MODULE_PARAM --other --pretext "module=$modname ; parameter=$modparam ; ; " --default "$paramval" || return 1
  2981.         paramval="$ANSWER"
  2982.     fi
  2983.     set_val -f $FILE_VALUES_SEL Value_Of_Param%${modname}%${modparam}%current "${paramval}"
  2984.     return 0
  2985. }
  2986.  
  2987. Ask_Module_Param()
  2988. {
  2989.     local modname="$1"
  2990.     local params
  2991.     local insmod_params="`get_val -f $FILE_VALUES_SEL Module_Params%${modname}%current`"
  2992.  
  2993.     Ask2 string MODULE_PARAM "$insmod_params" || return 1
  2994.     insmod_params="$ANSWER"
  2995.     set_val -f $FILE_VALUES_SEL Module_Params%${modname}%current "${insmod_params}"
  2996.     return 0
  2997. }
  2998.  
  2999. Menu_Module_Param()
  3000. {
  3001.     local modname="$1"
  3002.     local modparam
  3003.     local paramval
  3004.     local params
  3005.     local insmod_params
  3006.  
  3007.     params="`List_Param_Of_Module $FILE_MODULES_DATA $modname`"
  3008.     if [ -z "$params" ]; then
  3009.         Ask_Module_Param $modname || return 1
  3010.         insmod_params="$ANSWER"
  3011.     else
  3012.         while [ 1 ]; do
  3013.             Choose_Param_Of_Module "$modname" || return 1
  3014.             modparam="$ANSWER"
  3015.             if [ "$modparam" = "OTHER" ]; then
  3016.                 Ask_Module_Param $modname || continue
  3017.                 insmod_params="$ANSWER"
  3018.                 break
  3019.             fi
  3020.             if [ "$modparam" != "DONE" ]; then
  3021.                 Choose_Value_Of_Param "$modname" "$modparam" || continue
  3022.                 paramval="$ANSWER"
  3023.             else
  3024.                 insmod_params=
  3025.                 for modparam in `List_Param_Of_Module $FILE_MODULES_DATA $modname` ; do
  3026.                     paramval="`get_val -f $FILE_VALUES_SEL Value_Of_Param%${modname}%${modparam}%current`"
  3027.                     if [ -n "$paramval" ]; then
  3028.                         insmod_params="$insmod_params $modparam=${paramval}"
  3029.                     fi
  3030.                 done
  3031.                 break
  3032.             fi
  3033.         done
  3034.     fi
  3035.     ANSWER="$insmod_params"
  3036.     return 0
  3037. }
  3038.  
  3039.  
  3040. # Ask_Bool ( [--pretext PRETEXT] [--prehelp PREHELP] [--help ALTERNATE_HELP] [--text ALTERNATE_TEXT] VARNAME [DEFAULTVAL] )
  3041. #       Just ask a yes/no question
  3042. #
  3043. Ask_Bool()
  3044. {
  3045.     FUNC_NAME=Ask_Bool
  3046.     export ANSWER=
  3047.     local retval=
  3048.     local help=
  3049.     local text=
  3050.     local prehelp=
  3051.     local pretext=
  3052.  
  3053.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3054.  
  3055.     if [ $# -lt 1 ]; then
  3056.         Panic "got $# instead of at least 1 arg!"
  3057.     fi
  3058.  
  3059.     # look for pretext
  3060.     if [ $# -gt 2 ]; then
  3061.         if [ "$1" = '--pretext' ]; then
  3062.             pretext="$2"
  3063.             shift 2
  3064.         fi
  3065.     fi
  3066.  
  3067.     # look for prehelp
  3068.     if [ $# -gt 2 ]; then
  3069.         if [ "$1" = '--prehelp' ]; then
  3070.             prehelp="$2"
  3071.             shift 2
  3072.         fi
  3073.     fi
  3074.  
  3075.     # look for alternate help
  3076.     if [ $# -gt 2 ]; then
  3077.         if [ "$1" = '--help' ]; then
  3078.             help="$2"
  3079.             shift 2
  3080.         fi
  3081.     fi
  3082.  
  3083.     # look for alternate text
  3084.     if [ $# -gt 2 ]; then
  3085.         if [ "$1" = '--text' ]; then
  3086.             text="$2"
  3087.             shift 2
  3088.         fi
  3089.     fi
  3090.  
  3091.     if [ -z "$help" ]; then
  3092.         help=":ASK_$1_HELP:"
  3093.     fi
  3094.  
  3095.     if [ -z "$text" ]; then
  3096.         text=":ASK_$1_TEXT:"
  3097.     fi
  3098.  
  3099.     # build command header
  3100.     echo "$CMD_BOX --help \"${prehelp}${help}\" --title \":ASK_$1_TITLE:\" --bool \"${pretext}${text}\" \\" > $FILE_TMP_COMMAND
  3101.  
  3102.     # append default value if available
  3103.     if [ $# -gt 1 ]; then
  3104.         echo "--default \"$2\" \\" >> $FILE_TMP_COMMAND
  3105.     fi
  3106.  
  3107.     # build command trailer
  3108.     echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  3109.     chmod 755 $FILE_TMP_COMMAND
  3110.  
  3111.     # log command if requested
  3112.     Log_Cmd
  3113.  
  3114.     # execute command
  3115.     sh $FILE_TMP_COMMAND
  3116.     retval=$?
  3117.     if [ $retval -eq 0 ]; then
  3118.         ANSWER="`cat $FILE_TMP_ANSWER`"
  3119.     fi
  3120.     rm -f $FILE_TMP_COMMAND
  3121.     rm -f $FILE_TMP_ANSWER
  3122.     return $retval
  3123. }
  3124.  
  3125. # Ask_String ( [--pretext PRETEXT] VARNAME [DEFAULTVAL] )
  3126. #
  3127. # ask for a string
  3128. #
  3129. Ask_String()
  3130. {
  3131.     FUNC_NAME=Ask_String
  3132.     export ANSWER=
  3133.     local retval=
  3134.     local text=
  3135.     local help=
  3136.     local pretext=
  3137.     local prehelp=
  3138.  
  3139.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3140.  
  3141.     if [ $# -lt 1 ]; then
  3142.         Panic "got $# instead of at least 1 arg!"
  3143.     fi
  3144.  
  3145.     if [ $# -gt 2 -a "$1" = '--pretext' ]; then
  3146.         pretext="$2"
  3147.         shift 2
  3148.     fi
  3149.  
  3150.     if [ $# -gt 2 -a "$1" = '--prehelp' ]; then
  3151.         prehelp="$2"
  3152.         shift 2
  3153.     fi
  3154.  
  3155.     if [ $# -gt 2 -a "$1" = '--help' ]; then
  3156.         help="$2"
  3157.         shift 2
  3158.     else
  3159.         help=":ASK_$1_HELP:"
  3160.     fi
  3161.  
  3162.     text=":ASK_$1_TEXT:"
  3163.  
  3164.     # if [ $# -gt 1 ]; then
  3165.     #    $CMD_BOX --default "$2" --help "${prehelp}${help}" --title ":ASK_$1_TITLE:" --string "${pretext}${text}" 2> $FILE_TMP_ANSWER
  3166.     # else
  3167.     #     $CMD_BOX --help "${prehelp}${help}" --title ":ASK_$1_TITLE:" --string "${pretext}${text}" 2> $FILE_TMP_ANSWER
  3168.     # fi
  3169.     # retval=$?
  3170.  
  3171.     # build command header
  3172.     echo "$CMD_BOX --help \"${prehelp}${help}\" --title \":ASK_$1_TITLE:\" --string \"${pretext}${text}\" \\" > $FILE_TMP_COMMAND
  3173.  
  3174.     # append default value if available
  3175.     if [ $# -gt 1 ]; then
  3176.         echo "--default \"$2\" \\" >> $FILE_TMP_COMMAND
  3177.     fi
  3178.  
  3179.     # build command trailer
  3180.     echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  3181.     chmod 755 $FILE_TMP_COMMAND
  3182.  
  3183.     # log command if requested
  3184.     Log_Cmd
  3185.  
  3186.     # execute command
  3187.     sh $FILE_TMP_COMMAND
  3188.  
  3189.     retval=$?
  3190.     if [ $retval -eq 0 ]; then
  3191.         ANSWER="`cat $FILE_TMP_ANSWER`"
  3192.     else
  3193.         ANSWER=""
  3194.         Debug -D "Ask_String Output (Start)" 
  3195.         Debug -c cat $FILE_TMP_ANSWER
  3196.         Debug -D "Ask_String Output (End)" 
  3197.     fi
  3198.     rm -f $FILE_TMP_ANSWER
  3199.     return $retval
  3200. }
  3201.  
  3202. # Box ( TYPE [--var VAR] [--help HELP] [--text TEXT] [--title TITLE])
  3203. #            [--build ITMEMBUILDFUNCTION] [DEFAULTVAL])
  3204. #
  3205. # Box is a box frontend, returning answer in $ANSWER
  3206. #
  3207. #    box-types (TYPE):
  3208. #
  3209. # a) input boxes
  3210. #    bool
  3211. #    num
  3212. #    ip
  3213. #    string
  3214. #    one
  3215. #    menu
  3216. #    showlist
  3217. #    menulist
  3218. #
  3219. # b) output boxes
  3220. #    info
  3221. #    msg
  3222. #    browse
  3223. #    err
  3224. #    warn
  3225. #
  3226. # --var ask & set value of variable VAR
  3227. # --help replace standard-help with HELP
  3228. # --text replace standard-text with TEXT
  3229. # --title replace standard-title with TITLE
  3230. # --build use function BUILD to create itemlist
  3231. #
  3232.  
  3233. Box()
  3234. {
  3235.     FUNC_NAME=Box
  3236.     export ANSWER=
  3237.     local box_type=string
  3238.     local retval=
  3239.     local variable=BOX
  3240.     local title=
  3241.     local text=
  3242.     local help=
  3243.     local build=
  3244.     local defval=
  3245.     local file=
  3246.  
  3247.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3248.  
  3249.     # process options
  3250.     if [ $# -eq 0 ]; then
  3251.         Panic "$FUNC_NAME: panic! no box type specified!"
  3252.     fi
  3253.  
  3254.     # get box_type
  3255.     box_type="$1"
  3256.     shift 1
  3257.  
  3258.     case $box_type in
  3259.     bool)
  3260.         prefix=BOOL ;;
  3261.     num|ip|string)
  3262.         prefix=ASK ;;
  3263.     one|showlist)
  3264.         prefix=CHOOSE ;;
  3265.     menu|sumlist)
  3266.         prefix=MENU ;;
  3267.     msg|info|browse)
  3268.         prefix=INFO ;;
  3269.     err)
  3270.         box_type=browse
  3271.         prefix=ERR ;;
  3272.     warn)
  3273.         box_type=msg
  3274.         prefix=WARN ;;
  3275.     *)
  3276.         Panic "$FUNC_NAME: panic! invalid box type specified!";;
  3277.     esac
  3278.  
  3279.     # set standard help
  3280.     title=":${prefix}_${variable}_TITLE:"
  3281.     text=":${prefix}_${variable}_TEXT:"
  3282.     help=":${prefix}_${variable}_HELP:"
  3283.  
  3284.     while [ 1 ]; do
  3285.         if [ $# -eq 0 ]; then
  3286.             break
  3287.         elif [ $# -gt 1 ]; then
  3288.             # options that take arguments
  3289.             case $1 in
  3290.             --var)
  3291.                 variable="$2"
  3292.                 title=":${prefix}_${variable}_TITLE:"
  3293.                 text=":${prefix}_${variable}_TEXT:"
  3294.                 help=":${prefix}_${variable}_HELP:"
  3295.                 shift 2
  3296.                 continue;;
  3297.             --help)
  3298.                 help="$2"
  3299.                 shift 2
  3300.                 continue;;
  3301.             --title)
  3302.                 title="$2"
  3303.                 shift 2
  3304.                 continue;;
  3305.             --text)
  3306.                 text="$2"
  3307.                 shift 2
  3308.                 continue;;
  3309.             --build)
  3310.                 build="$2"
  3311.                 shift 2
  3312.                 continue;;
  3313.             esac
  3314.         else
  3315.             # flags that take no arguments
  3316.             if [ $# -eq 1 ]; then
  3317.                 # last argument is a default value or a file to browse
  3318.                 if [ "$box_type" = "browse" ]; then
  3319.                     file="$1"
  3320.                     shift 1
  3321.                     continue
  3322.                 else
  3323.                     defval="$1"
  3324.                     shift 1
  3325.                     continue
  3326.                 fi
  3327.             fi
  3328.         fi
  3329.         Panic "$FUNC_NAME: panic! invalid arguments $* !"
  3330.     done
  3331.  
  3332.     # command header
  3333.     echo -n "$CMD_BOX " > $FILE_TMP_COMMAND
  3334.  
  3335.     # command options
  3336.     if [ -n "$help" ]; then
  3337.         echo "--help \"$help\" \\" >> $FILE_TMP_COMMAND
  3338.     fi
  3339.     if [ -n "$title" ]; then
  3340.         echo "--title \"$title\" \\" >> $FILE_TMP_COMMAND
  3341.     fi
  3342.     if [ "$box_type" = "browse" ]; then
  3343.         echo "--text \"$text\" \\" >> $FILE_TMP_COMMAND
  3344.         echo "--browse $file \\" >> $FILE_TMP_COMMAND
  3345.     else
  3346.         echo "--$box_type \"$text\" \\" >> $FILE_TMP_COMMAND
  3347.     fi
  3348.     if [ -n "$defval" ]; then
  3349.         echo "--default \"$defval\" \\" >> $FILE_TMP_COMMAND
  3350.     fi
  3351.  
  3352.     # command items
  3353.     if [ -n "$build" ]; then
  3354.         # call build-function to build menu items
  3355.         $build > $FILE_TMP_MSG
  3356.         if [ -s $FILE_TMP_MSG ]; then
  3357.             cat $FILE_TMP_MSG >> $FILE_TMP_COMMAND
  3358.             rm -f $FILE_TMP_MSG
  3359.         else
  3360.             rm -f $FILE_TMP_COMMAND
  3361.             rm -f $FILE_TMP_ANSWER
  3362.             Panic "$FUNC_NAME: panic! empty list of items!"
  3363.         fi
  3364.     fi
  3365.  
  3366.     # command trailer
  3367.     echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  3368.     chmod 755 $FILE_TMP_COMMAND
  3369.  
  3370.     # log command if requested
  3371.     Log_Cmd
  3372.  
  3373.     # execute command
  3374.     sh $FILE_TMP_COMMAND
  3375.     retval=$?
  3376.     if [ "$box_type" = "info" ]; then
  3377.         sleep 1
  3378.     fi
  3379.     if [ $retval -eq 0 ]; then
  3380.         if [ "$box_type" != "sumlist" ]; then
  3381.             ANSWER="`cat $FILE_TMP_ANSWER`"
  3382.             rm -f $FILE_TMP_ANSWER
  3383.         fi
  3384.     fi
  3385.     rm -f $FILE_TMP_COMMAND
  3386.     return $retval
  3387. }
  3388.  
  3389. Browse()
  3390. {
  3391.   FUNC_NAME=Browse
  3392.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3393.   if [ $# -eq 2 ]; then
  3394.     Box browse --text "$2" $1 || return 1
  3395.     return 0
  3396.   else
  3397.     Box browse $1 || return 1
  3398.     return 0
  3399.   fi
  3400. }
  3401.  
  3402. Browse2()
  3403. {
  3404.   FUNC_NAME=Browse2
  3405.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3406.   Box browse --var "$2" $1 || return 1
  3407.   return 0
  3408. }
  3409.  
  3410. # Choose ( [--none] [--other] [--prefix PREFIX] [--menutitle MENUTITLE] [--build MENUBUILDFUNCTION] VARNAME [CONFVARNAME] )
  3411. #
  3412. # ask for one out of many choices
  3413. #
  3414. Choose()
  3415. {
  3416.     FUNC_NAME=Choose
  3417.     export ANSWER=
  3418.     local retval=
  3419.     local box_type=one
  3420.     local one_flag=
  3421.     local other_flag=
  3422.     local none_flag=
  3423.     local menu_title=
  3424.     local build_function=
  3425.     local confval=
  3426.     local defval=
  3427.     local prefix=
  3428.  
  3429.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3430.  
  3431.     while [ 1 ]; do
  3432.         if [ $# -gt 1 ]; then
  3433.             case $1 in 
  3434.             --build)
  3435.                 build_function="$2"
  3436.                 shift 2
  3437.                 continue;;
  3438.             --default)
  3439.                 defval="$2"
  3440.                 shift 2
  3441.                 continue;;
  3442.             --menutitle)
  3443.                 menu_title="$2"
  3444.                 shift 2
  3445.                 continue;;
  3446.             --prefix)
  3447.                 prefix="$2"
  3448.                 shift 2
  3449.                 continue;;
  3450.             --none)
  3451.                 none_flag=true
  3452.                 shift 1
  3453.                 continue;;
  3454.             --other)
  3455.                 other_flag=true
  3456.                 shift 1
  3457.                 continue;;
  3458.             --menu)
  3459.                 box_type=menu
  3460.                 shift 1
  3461.                 continue;;
  3462.             --multi)
  3463.                 box_type=multi
  3464.                 shift 1
  3465.                 continue;;
  3466.             --sumlist)
  3467.                 box_type=sumlist
  3468.                 shift 1
  3469.                 continue;;
  3470.             --onelist)
  3471.                 box_type=sumlist
  3472.                 one_flag='-O'
  3473.                 shift 1
  3474.                 continue;;
  3475.             --showlist)
  3476.                 box_type=showlist
  3477.                 shift 1
  3478.                 continue;;
  3479.             *)
  3480.                 break;;
  3481.             esac
  3482.         else
  3483.             break
  3484.         fi
  3485.     done
  3486.  
  3487.     if [ $# -lt 1 ]; then
  3488.         Panic "got $# instead of at least 1 args!"
  3489.     fi
  3490.  
  3491.     # build command header
  3492.     if [ -z "$prefix" ]; then
  3493.         case $box_type in
  3494.         one|showlist)
  3495.             prefix=CHOOSE
  3496.             ;;
  3497.         menu|sumlist|multi)
  3498.             prefix=MENU
  3499.             ;;
  3500.         esac
  3501.     fi
  3502.     echo "$CMD_BOX $one_flag --help \":${prefix}_$1_HELP:\" \\" > $FILE_TMP_COMMAND
  3503.     echo "--title \":${prefix}_$1_TITLE:\" \\" >> $FILE_TMP_COMMAND
  3504.     echo "--$box_type \":${prefix}_$1_TEXT:\" \\" >> $FILE_TMP_COMMAND
  3505.  
  3506.     # append default value if available
  3507.     if [ $# -gt 1 ]; then
  3508.         confval="`Get_Val $2`"
  3509.         if [ -n "$confval" ]; then
  3510.             echo "--default \"$confval\" \\" >> $FILE_TMP_COMMAND
  3511.         else
  3512.             echo "--default \"$2\" \\" >> $FILE_TMP_COMMAND
  3513.         fi
  3514.     elif [ -n "$defval" ]; then
  3515.         echo "--default \"$defval\" \\" >> $FILE_TMP_COMMAND
  3516.     fi
  3517.  
  3518.     if [ -n "$menu_title" ]; then
  3519.         echo "--menutitle \"$menu_title\" \\" >> $FILE_TMP_COMMAND
  3520.     fi
  3521.  
  3522.     rm -f $FILE_TMP_MSG
  3523.     if [ -n "$none_flag" ]; then
  3524.         Debug "NONE item allowed"
  3525.         echo "\"\" \":TYPE_$1_NONE:\" \\"  >> $FILE_TMP_MSG
  3526.     fi
  3527.     if [ -n "$other_flag" ]; then
  3528.         Debug "OTHER item allowed"
  3529.         Is_Expert && echo "\"other\" \":DEVICE_DIRECT:\" \\"  >> $FILE_TMP_MSG
  3530.     fi
  3531.  
  3532.     # build command header
  3533.     if [ -z "$build_function" ]; then
  3534.         build_function="List box $1"
  3535.     fi
  3536.  
  3537.     Debug "build item list with <$build_function>"
  3538.     # call build-function to build menu items
  3539.     $build_function >> $FILE_TMP_MSG
  3540.     if [ $? -ne 0 ]; then
  3541.         Debug "Error: return val != 0"
  3542.         Debug "Error: $ERROR"
  3543.         Error "$ERROR"
  3544.         return 1
  3545.     fi
  3546.     if [ -s $FILE_TMP_MSG ]; then
  3547.         cat $FILE_TMP_MSG >> $FILE_TMP_COMMAND
  3548.         rm -f $FILE_TMP_MSG
  3549.     else
  3550.         Debug "empty list. responsible command was"
  3551.         Debug -c cat $FILE_TMP_COMMAND 
  3552.         Error ":ERR_EMPTY_SELECTLIST:"
  3553.         return 1
  3554.     fi
  3555.  
  3556.     # build command trailer
  3557.     echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  3558.     chmod 755 $FILE_TMP_COMMAND
  3559.  
  3560.     # log command if requested
  3561.     Log_Cmd
  3562.  
  3563.     # execute command
  3564.     Debug "Executing command: 'sh $FILE_TMP_COMMAND'"
  3565.     Debug -D "----- $FILE_TMP_COMMAND"
  3566.     Debug -c cat $FILE_TMP_COMMAND
  3567.     Debug -D "----- "
  3568.     sh $FILE_TMP_COMMAND
  3569.     retval=$?
  3570.     Debug "retval is $retval"
  3571.     if [ $retval -eq 0 ]; then
  3572.         ANSWER="`cat $FILE_TMP_ANSWER`"
  3573.         case $box_type in
  3574.         one)
  3575.             if [ "$ANSWER" = "other" ]; then
  3576.                 Ask_String $1 $confval
  3577.                 retval=$?
  3578.                 # ANSWER is set by Ask_String
  3579.             fi
  3580.             rm -f $FILE_TMP_ANSWER
  3581.             ;;
  3582.         menu|onelist|showlist)
  3583.             rm -f $FILE_TMP_ANSWER
  3584.             ;;
  3585.         sumlist|multi)
  3586.             # do not set ANSWER but keep $FILE_TMP_ANSWER
  3587.             ;;
  3588.         esac
  3589.     fi
  3590.     rm -f $FILE_TMP_COMMAND
  3591.     return $retval
  3592. }
  3593.  
  3594. Info()
  3595. {
  3596.   FUNC_NAME=Info
  3597.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3598.   Box info --text "$@" || return 1
  3599.   return 0
  3600. }
  3601.  
  3602. Info_lite()
  3603. {
  3604.   FUNC_NAME=Info_lite
  3605.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3606.   $CMD_BOX --info "$@" || return 1
  3607.   sleep 1
  3608.   return 0
  3609. }
  3610.  
  3611. List()
  3612. {
  3613.     local CD_DEV_LIST="aztcd cdu31a cdu535 cm206cd gscd mcd mcdx optcd sbpcd scd0 scd1 sjcd hda hdb hdc hdd arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd"
  3614.     local CUA_LIST="cua0 cua1 cua2 cua3"
  3615.     local FLOPPY_DEV_LIST="E2880 H1440 H720 D720 H360 D360 h1200 h720 h360 d360"
  3616.     local KERNTZ_LIST="UTCTIME LOCALTIME"
  3617.     local NIS_LIST="CLIENT SERVER"
  3618.     local PARALLEL_DEV_LIST="lp0 lp1 lp2"
  3619.     # all possibles gs devices
  3620.     # local PRINTER_LIST="apple bj10e bj200 lbp8 m8510 la50 la75 declj250 lj250 ln03 epson eps9high epsonc escp2 cdeskjet cdjcolor cdjmono deskjet djet500 djet500c cdj550 laserjet ljet2p ljet3 ljet4 ljetplus paintjet pj pjxl pjxl300 jetp3852 ibmpro necp6 oki ricoh sparc t4693d2 t4693d4 t4693d8 t4695"
  3621.     # available devices in gs 2.6.2
  3622.     # local PRINTER_LIST="bj10e bj200 cdeskjet cdjcolor cdjmono cdj550 djet500 djet500c ljet2p ljet3 ljet4 ljetplus paintjet epson escp2 necp6"
  3623.     # available devices in gs 3.33
  3624.     local PRINTER_LIST="NET PostScript bj200 bj10e lbp8 m8510 la50 la75 declj250 ln03 eps9high epsonc epson stcolor cdjcolor djet500 djet500c cdj500 cdeskjet cdj550 laserjet ljet2p ljet3 ljet4 ljetplus cdjmono pjxl300 pjtest paintjet pjxltest ibmpro necp6 sparc t4693d2 t4693d4 t4693d8"
  3625.     local PRINTER_PAPER="a3 a4 a5 letter legal ledger"
  3626.     local PRINTER_RES="75x75 150x150 180x180 180x360 300x300 360x360 400x400 600x600 720x720 800x800"
  3627.     local SERIAL_DEV_LIST="ttyS0 ttyS1 ttyS2 ttyS3"
  3628.     local SERIAL_SPEED_LIST="115200 57600 38400 19200 9600 2400 1200"
  3629.     local SHELL_LIST="sh bash ash csh tcsh pdksh zsh"
  3630.     local TAPE_DEV_LIST="st0 st1 tpqic11 tpqic24 ftape tpqic120 tpqic150"
  3631.     local TERM_LIST="linux linux-mono vt100"
  3632.     local TIMEZONE_LIST="Australia/ACT Australia/Adelaide Australia/Brisbane Australia/Broken_Hill Australia/Canberra Australia/Darwin Australia/Hobart Australia/LHI Australia/Lindeman Australia/Lord_Howe Australia/Melbourne Australia/NSW Australia/North Australia/Perth Australia/Queensland Australia/South Australia/Sydney Australia/Tasmania Australia/Victoria Australia/West Australia/Yancowinna Brazil/Acre Brazil/DeNoronha Brazil/East Brazil/West CET Canada/Atlantic Canada/Central Canada/East-Saskatchewan Canada/Eastern Canada/Mountain Canada/Newfoundland Canada/Pacific Canada/Saskatchewan Canada/Yukon Chile/Continental Chile/EasterIsland Cuba EET Egypt Factory GB Eire GMT GMT+0 GMT+1 GMT+10 GMT+11 GMT+12 GMT+13 GMT+2 GMT+3 GMT+4 GMT+5 GMT+6 GMT+7 GMT+8 GMT+9 GMT-0 GMT-1 GMT-10 GMT-11 GMT-12 GMT-2 GMT-3 GMT-4 GMT-5 GMT-6 GMT-7 GMT-8 GMT-9 GMT0 GMT1 GMT10 GMT11 GMT12 GMT13 GMT2 GMT3 GMT4 GMT5 GMT6 GMT7 GMT8 GMT9 Greenwich Hongkong Iceland Iran Israel Jamaica Japan Libya MET Mexico/BajaNorte Mexico/BajaSur Mexico/General NZ Navajo PRC Poland ROC ROK Singapore SystemV/AST4 SystemV/AST4ADT SystemV/CST6 SystemV/CST6CDT SystemV/EST5 SystemV/EST5EDT SystemV/HST10 SystemV/MST7 SystemV/MST7MDT SystemV/PST8 SystemV/PST8PDT SystemV/YST9 SystemV/YST9YDT Turkey UCT US/Alaska US/Aleutian US/Arizona US/Central US/East-Indiana US/Eastern US/Hawaii US/Michigan US/Mountain US/Pacific US/Pacific-New US/Samoa UTC Universal W-SU WET Zulu"
  3633.     local X_SERVER_LIST
  3634.     local tag_prefix=
  3635.     local label_prefix=
  3636.     local items=
  3637.     local current=
  3638.     local show_type=raw
  3639.  
  3640.     if Is_SPARC ; then
  3641.         X_SERVER_LIST="Xsun Xsun24 XsunMono"
  3642.     else
  3643.         X_SERVER_LIST="Xaccel XF86_Mono XF86_VGA16 XF86_SVGA XF86_S3 XF86_S3V XF86_W32 XF86_Mach64 XF86_Mach32 XF86_Mach8 XF86_AGX XF86_P9000 XF86_8514 XF86_I128 Xmetro"
  3644.     fi
  3645.  
  3646.     if [ $# -gt 0 -a "$1" = "box" ]; then
  3647.         show_type=box
  3648.         shift 1
  3649.     fi
  3650.  
  3651.     if [ $# -eq 0 ]; then 
  3652.         Debug "no arg passed to List"
  3653.         Panic "List called without any arguments"
  3654.         return 1
  3655.     fi 
  3656.  
  3657.     case $1 in
  3658.     CD_DEV)    
  3659.         items="$CD_DEV_LIST"
  3660.         tag_prefix="/dev/"
  3661.         label_prefix="TYPE_CD_"
  3662.         ;;
  3663.     FLOPPY_DEV)
  3664.         items="$FLOPPY_DEV_LIST"
  3665.         tag_prefix="/dev/fd$2"
  3666.         label_prefix="TYPE_FLOPPY_"
  3667.         ;;
  3668.     KERNTZ)
  3669.         items="$KERNTZ_LIST"
  3670.         tag_prefix="KTZ_"
  3671.         label_prefix="TYPE_KERNTZ_"
  3672.         ;;
  3673.     NIS)
  3674.         items="$NIS_LIST"
  3675.         tag_prefix=""
  3676.         label_prefix="TYPE_NIS_"
  3677.         ;;
  3678.     PARALLEL_DEV)
  3679.         items="$PARALLEL_DEV_LIST"
  3680.         tag_prefix="/dev/"
  3681.         label_prefix="TYPE_PARALLEL_DEV_"
  3682.         ;;
  3683.     PRINTER)
  3684.         items="$PRINTER_LIST"
  3685.         label_prefix="TYPE_PRINTER_"
  3686.         ;;
  3687.     PRINTER_PAPER)
  3688.         items="$PRINTER_PAPER"
  3689.         label_prefix=""
  3690.         ;;
  3691.     PRINTER_RES)
  3692.         items="$PRINTER_RES"
  3693.         label_prefix=""
  3694.         ;;
  3695.     SERIAL_SPEED)
  3696.         items="$SERIAL_SPEED_LIST"
  3697.         label_prefix="TYPE_SPEED_B"
  3698.         ;;
  3699.     SERIAL_DEV)
  3700.         items="$SERIAL_DEV_LIST"
  3701.         tag_prefix="/dev/"
  3702.         label_prefix="TYPE_SERIAL_DEV_"
  3703.         ;;
  3704.     SHELL)
  3705.         items=""
  3706.         for current in $SHELL_LIST; do
  3707.             if [ -f $DIR_TARGET/bin/$current ]; then
  3708.                 items="$items $current"
  3709.             fi
  3710.         done
  3711.         tag_prefix="/bin/"
  3712.         label_prefix="TYPE_SHELL_"
  3713.         ;;
  3714.     TAPE_DEV)
  3715.         items="$TAPE_DEV_LIST"
  3716.         tag_prefix="/dev/"
  3717.         label_prefix="TYPE_TAPE_"
  3718.         ;;
  3719.     TERM)
  3720.         items="$TERM_LIST"
  3721.         label_prefix="TYPE_TERM_"
  3722.         ;;
  3723.     TIMEZONE)
  3724.         items="$TIMEZONE_LIST"
  3725.         label_prefix=""
  3726.         ;;
  3727.     X_SERVER)
  3728.         items=""
  3729.         for current in $X_SERVER_LIST; do
  3730.           if [  -f /usr/X11R6/bin/$current -o \
  3731.             -f $DIR_TARGET/usr/X11R6/bin/$current ]; then
  3732.                  items="$items $current"
  3733.           fi
  3734.         done
  3735.         label_prefix="TYPE_X_SERVER_"
  3736.         ;;
  3737.     *)
  3738.         Debug "fallback: calling from List old function <Build_$1>"
  3739.         Build_$1
  3740.         return 0
  3741.         ;;
  3742.     esac
  3743.     for current in $items ; do
  3744.         if [ "$show_type" = "raw" ]; then
  3745.             echo "${tag_prefix}${current} :${label_prefix}${current}:"
  3746.         elif [ "$show_type" = "box" ]; then
  3747.             if [ -n "$label_prefix" ]; then
  3748.                 # FIXME: special handling for PostScript
  3749.                 if [ "$current" = "PostScript" ];  then
  3750.                     echo "\"${tag_prefix}${current}\" \"Local PostScript Printer\" \\"
  3751.                 else
  3752.                     echo "\"${tag_prefix}${current}\" \":${label_prefix}${current}:\" \\"
  3753.                 fi
  3754.             else
  3755.                 echo "\"${tag_prefix}${current}\" \"${current}\" \\"
  3756.             fi
  3757.         else
  3758.             echo "unsupported show_type <$show_type>"
  3759.             return 1
  3760.         fi
  3761.     done
  3762.     return 0
  3763. }
  3764.  
  3765. Msg()
  3766. {
  3767.   FUNC_NAME=Msg
  3768.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3769.   Box msg --text "$@" || return 1
  3770.   return 0
  3771. }
  3772.  
  3773. Msg2()
  3774. {
  3775.   FUNC_NAME=Msg2
  3776.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3777.   Box msg --var "$1" || return 1
  3778.   return 0
  3779. }
  3780.  
  3781. # libLSTdebug - Debug functions shared between several scripts
  3782. #
  3783. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  3784. #
  3785.  
  3786. Call_Direct()
  3787. {
  3788.     local cmd
  3789.     local retval
  3790.  
  3791.     echo
  3792.     echo -n "please enter name of function to call: "
  3793.     read cmd
  3794.     History "`date` Call_Direct: calling <$cmd>"
  3795.     $cmd
  3796.     retval=$?
  3797.     History "`date` Call_Direct: command <$cmd> returned with <$retval>"
  3798.     echo
  3799.     echo "command <$cmd> returned with <$retval>"
  3800. }
  3801.  
  3802. Debug()
  3803. {
  3804.     local screen=true
  3805.     local timestamp=true
  3806.     local command=
  3807.     local pipe=
  3808.     local disk_log=
  3809.     local permanent=$DIR_TARGET/var/adm/LST/log
  3810.  
  3811.     if [ "$MODE_DEBUG" != "true" ]; then
  3812.         return 0
  3813.     fi
  3814.     if [ -d $permanent ]; then
  3815.         disk_log=$permanent/debug
  3816.     fi
  3817.     if [ "X$1" = "X-d" -o "X$1" = "X--diskonly" ]; then
  3818.         screen=
  3819.         shift
  3820.     fi
  3821.     if [ "X$1" = "X-n" -o "X$1" = "X--nostamp" ]; then
  3822.         timestamp=
  3823.         shift
  3824.     fi
  3825.     if [ "X$1" = "X-D" -o "X$1" = "X--disk-nostamp" ]; then
  3826.         screen=
  3827.         timestamp=
  3828.         shift
  3829.     fi
  3830.     if [ "X$1" = "X-c" -o "X$1" = "X--command" ]; then
  3831.         screen=
  3832.         timestamp=
  3833.         shift
  3834.         command="$*"
  3835.     fi
  3836.     if [ "X$1" = "X-p" -o "X$1" = "X--pipe" ]; then
  3837.         timestamp=
  3838.         pipe=true
  3839.         shift
  3840.     fi
  3841.  
  3842.     if [ -n "$command" -a -n "$disk_log" ]; then
  3843.         $command >> $disk_log 2>&1
  3844.         return 0
  3845.     fi
  3846.     if [ -n "$pipe" ]; then
  3847.         if [ -n "$disk_log" ]; then
  3848.             tee -a $disk_log >> $FILE_TMP_DEBUG
  3849.         else
  3850.             cat - >> $FILE_TMP_DEBUG
  3851.         fi
  3852.         return 0
  3853.     fi
  3854.     if [ -n "$screen" ]; then
  3855.         echo "`date` debug: $@" >> $FILE_TMP_DEBUG
  3856.     fi
  3857.     if [ -z "$disk_log" ]; then
  3858.         return 0
  3859.     fi
  3860.     if [ -n "$timestamp" ]; then
  3861.         echo "`date` debug: $@" >> $disk_log
  3862.     else
  3863.         echo "$@" >> $disk_log
  3864.     fi
  3865. }
  3866.  
  3867. Log_Cmd()
  3868. {
  3869.     local num
  3870.  
  3871.     if [ -f /tmp/.log ]; then
  3872.         num="`cat /tmp/.log`"
  3873.         if [ -z "$num" ]; then
  3874.             num=0
  3875.         fi
  3876.         num="`do_calc $num + 1`"
  3877.         echo "$num" > /tmp/.log
  3878.         cp -a $FILE_TMP_COMMAND /var/adm/LST/log/cmd.$num
  3879.         echo "debug: cmd $num saved to /var/adm/LST/log/cmd.$num" > /dev/tty5
  3880.         echo "debug: calling cmd $num:" > /dev/tty5
  3881.     fi
  3882. }
  3883.  
  3884. Debug_Stop()
  3885. {
  3886.     local debug_ans
  3887.     echo "Debug_Stop called. Press <Enter> to continue."
  3888.     read debug_ans
  3889. }
  3890.  
  3891. # Do_Log ( [-d] [-n] [-f FILE] text_to_log )
  3892. #
  3893. # Log a string for logging or postponed display
  3894. # Should be usable instead of echo.
  3895. #
  3896. # Options:
  3897. # -d        delete file
  3898. # -n        do not append newline
  3899. # -f FILE    log to file FILE
  3900. #
  3901. Do_Log()
  3902. {
  3903.     local deleteflag=
  3904.     local appendflag=
  3905.     local logfile=$FILE_TMP_LOG
  3906.  
  3907.     # parse loop
  3908.     while [ 1 ]; do
  3909.         if [ $# -gt 1 -a "X$1" = 'X-f' ]; then
  3910.                 logfile=$2
  3911.                 shift 2
  3912.         elif [ $# -gt 0 ]; then
  3913.             if [ "X$1" = 'X-d' ]; then
  3914.                 deleteflag=true
  3915.                 shift 1
  3916.             elif [ "X$1" = 'X-n' ]; then
  3917.                 appendflag=true
  3918.                 shift 1
  3919.             else
  3920.                 # no more options, so the rest is message
  3921.                 break
  3922.             fi
  3923.         fi
  3924.     done
  3925.     Debug --nostamp "$@"
  3926.     if [ -n "$deleteflag" ]; then
  3927.         rm -f "$logfile"
  3928.     fi
  3929.     if [ -n "$appendflag" ]; then
  3930.         echo -n "$@" >> $logfile
  3931.     else
  3932.         echo "$@" >> $logfile
  3933.     fi
  3934. }
  3935.  
  3936. Disable_Auto_Mode()
  3937. {
  3938.     CMD_BOX="box"
  3939.     set_val -f /etc/lst.cnf CMD_BOX "box"
  3940.     MODE_QUERY="prompt"
  3941.     set_val MODE_QUERY prompt
  3942.     MODE_SPEED="normal"
  3943.     set_val MODE_SPEED normal
  3944.     return 0
  3945. }
  3946.  
  3947. Error()
  3948. {
  3949.     local error_help=
  3950.     local error_text=
  3951.     local error_file=
  3952.  
  3953.     echo -n ""
  3954.     # swvc 1
  3955.     if [ $# -gt 1 -a "$1" = '--file' ]; then
  3956.         error_file="$2"
  3957.         shift 2
  3958.     fi
  3959.     if [ $# -gt 1 -a "$1" = '--help' ]; then
  3960.         error_help="$2"
  3961.         shift 2
  3962.     else
  3963.         error_help=":HELP_ERROR:"
  3964.     fi
  3965.     if [ $# -gt 0 ]; then
  3966.         error_text=":ERR_MSG_WAS: ; ; $@ ; "
  3967.     else
  3968.         error_text=":ERR_IS_UNKNOWN:"
  3969.     fi
  3970.  
  3971.     History "`date` error: $error_text"
  3972.     if [ -z "$error_file" ]; then
  3973.         $CMD_BOX --title ":ERROR:" --help "$error_help" --msg "$error_text"
  3974.     else
  3975.         if [ -s $error_file ]; then
  3976.             History "error log in $error_file:"
  3977.             History "`cat $error_file`"
  3978.             $CMD_BOX --title ":ERROR:" --help "$error_help" --text "$error_text" --browse $error_file
  3979.             rm -f $error_file
  3980.         else
  3981.             $CMD_BOX --title ":ERROR:" --help "$error_help" --msg "$error_text"
  3982.         fi
  3983.     fi
  3984.     Disable_Auto_Mode
  3985.     return 0
  3986. }
  3987.  
  3988. Error2()
  3989. {
  3990.     echo -n ""
  3991.     # swvc 1
  3992.     echo "--------------------------------" >> $FILE_TMP_ERR
  3993.     History "`date` error: $@"
  3994.     History "`cat $FILE_TMP_ERR`"
  3995.     Disable_Auto_Mode
  3996.     Box err --var "$1" $FILE_TMP_ERR || return 1
  3997.     return 0
  3998. }
  3999.  
  4000. Err_Not_Available()
  4001. {
  4002.     Error --help ":HELP_NOT_AVAILABLE:" ":INFO_NOT_AVAILABLE:"
  4003. }
  4004.  
  4005. Err_Not_Implemented()
  4006. {
  4007.     Error --help ":HELP_NOT_IMPLEMENTED:" ":INFO_NOT_IMPLEMENTED:"
  4008. }
  4009.  
  4010. History()
  4011. {
  4012.     Do_Log -f $FILE_LOG_HISTORY "$@"
  4013. }
  4014.  
  4015. History_Install()
  4016. {
  4017.     History "`date` $LOGNAME: $PKG_NAME: $@"
  4018. }
  4019.  
  4020. Panic()
  4021. {
  4022.     History "`date` panic: $@"
  4023.     echo
  4024.     echo "Panic!"
  4025.     echo "$@"
  4026.     echo
  4027.     while [ 1 ]; do
  4028.         echo -n "abort (a), continue (c), show var (v), set var (s), call function (f): "
  4029.         read ans
  4030.         if [ "$ans" = "a" ]; then
  4031.             History "`date` panic: abort and exit."
  4032.             reset
  4033.             exit 1
  4034.         elif [ "$ans" = "v" ]; then
  4035.             History "`date` panic: continue with Show_Value."
  4036.             Show_Value
  4037.         elif [ "$ans" = "s" ]; then
  4038.             History "`date` panic: continue with Set_Value."
  4039.             Set_Value
  4040.         elif [ "$ans" = "f" ]; then
  4041.             History "`date` panic: continue with Call_Direct."
  4042.             Call_Direct
  4043.         elif [ "$ans" = "c" ]; then
  4044.             History "`date` panic: try to continue."
  4045.             return 0
  4046.         fi
  4047.     done
  4048. }
  4049.  
  4050. Set_Value()
  4051. {
  4052.     local var
  4053.     local value
  4054.  
  4055.     echo -n "enter name of variable to set: "
  4056.     read var
  4057.     echo -n "enter value of $var: "
  4058.     read value
  4059.     echo "export $var=\"$value\"" > /tmp/val
  4060.     . /tmp/val
  4061.     History "`date` Set_Value: value of <$var> set to <$value>"
  4062.     rm -f /tmp/val
  4063. }
  4064.  
  4065. Show_Value()
  4066. {
  4067.     local var
  4068.  
  4069.     echo -n "enter name of variable to show: "
  4070.     read var
  4071.     eval "echo \"\$$var\"" > /tmp/val
  4072.     echo "$var=<`cat /tmp/val`>"
  4073.     History "`date` Show_Value: value of <$var> is <`cat /tmp/val`>"
  4074.     rm -f /tmp/val
  4075. }
  4076.  
  4077. Simulate()
  4078. {
  4079.   $CMD_BOX --help ":MENU_SIMULATE_HELP:" --title ":MENU_SIMULATE_TITLE:" --msg ":MENU_SIMULATE_TEXT: ; ; $*" 2> /dev/null
  4080. }
  4081.  
  4082. Warn()
  4083. {
  4084.     local warn_help=
  4085.     local warn_text=
  4086.     local warn_file=
  4087.  
  4088.     if [ $# -gt 1 -a "$1" = '--file' ]; then
  4089.         warn_file="$2"
  4090.         shift 2
  4091.     fi
  4092.     if [ $# -gt 1 -a "$1" = '--help' ]; then
  4093.         warn_help="$2"
  4094.         shift 2
  4095.     else
  4096.         warn_help=":HELP_WARNING:"
  4097.     fi
  4098.     if [ $# -gt 0 ]; then
  4099.         warn_text=":WARNING: ! ; ; $@ ; "
  4100.     else
  4101.         warn_text=":WARNING: !"
  4102.     fi
  4103.  
  4104.     History "`date` warn: $warn_text"
  4105.     if [ -z "$warn_file" ]; then
  4106.         $CMD_BOX --title ":WARNING:" --help "$warn_help" --msg "$warn_text" || return 1
  4107.     else
  4108.         if [ -f $warn_file ]; then
  4109.             echo "--------------------------" >> $warn_file
  4110.             History "error log in $warn_file:"
  4111.             History "`cat $warn_file`"
  4112.             $CMD_BOX --title ":WARNING:" --help "$warn_help" --text "$warn_text" --browse $warn_file || return 1
  4113.             rm -f $warn_file
  4114.         else
  4115.             $CMD_BOX --title ":WARNING:" --help "$warn_help" --msg "$warn_text" || return 1
  4116.         fi
  4117.     fi
  4118.     return 0
  4119. }
  4120.  
  4121. Warn2()
  4122. {
  4123.     History "`date` warn: $1"
  4124.     Box warn --var "$1" || return 1
  4125.     return 0
  4126. }
  4127.  
  4128. # libLSTanalyse
  4129.  
  4130. Write_Analyse_Infos()
  4131. {
  4132.   local was_mounted=
  4133.   local extension=0
  4134.   local rfile=
  4135.   local i
  4136.  
  4137.   mount | fgrep 'on /floppy' > /dev/null && was_mounted=true
  4138.   umount /floppy >/dev/null 2>&1
  4139.   Msg ":DO_INSERT_DOS_FLOPPY:" || return 0
  4140.   mount -t msdos /dev/fd0H1440 /floppy
  4141.   if [ $? -ne 0 ]; then
  4142.     Msg ":ERR_MOUNT_FLOPPY_FAILED:"
  4143.   else
  4144.     Info ":INFO_ANALYSE_RUNNING:"
  4145.     while [ 1 ]; do
  4146.       if [ ! -f /floppy/analyse.$extension ]; then
  4147.     break
  4148.       else
  4149.     extension="`do_calc $extension + 1`"
  4150.       fi
  4151.     done
  4152.     rfile="/floppy/analyse.$extension"
  4153.     echo "=== report from `sysinfo --version` ===" > $rfile
  4154.     sysinfo >> $rfile
  4155.     for i in /proc/interrupts /proc/ioports /proc/dma /proc/pci /proc/cpuinfo /proc/modules /proc/devices /proc/net/dev /var/adm/LST/analyse/boot.params /var/adm/LST/analyse/boot.msg ; do
  4156.       if [ -f $i ]; then
  4157.     echo "=== $i ===" >> $rfile
  4158.     cat $i >> $rfile
  4159.       fi
  4160.     done
  4161.     echo "=== current dmesg output at `date` ===" >> $rfile
  4162.     dmesg >> $rfile
  4163.  
  4164.     if [ $? -ne 0 ]; then
  4165.       Msg ":ERR_WRITE_FAILED:"
  4166.     else
  4167.       sync
  4168.       sync
  4169.       umount /floppy >/dev/null 2>&1
  4170.       Msg "analyse.$extension ; :INFO_WRITE_SUCCEEDED:"
  4171.     fi
  4172.   fi
  4173.   while [ 1 ]; do
  4174.     umount /floppy >/dev/null 2>&1
  4175.     if [ -z "$was_mounted" ]; then return 0 ; fi
  4176.     Msg ":DO_INSERT_MODULES_FLOPPY:" || return 1
  4177.     mount -r /dev/fd0H1440 /floppy && break
  4178.     Msg ":ERR_MOUNT_FLOPPY_FAILED:" || return 1
  4179.   done
  4180.   return 0
  4181. }
  4182.  
  4183.  
  4184. Show_Boot_Msg()
  4185. {
  4186.   dmesg > $FILE_BOOT_MSG
  4187.   if [ -f $FILE_BOOT_MSG ]; then
  4188.     $CMD_BOX --title "$FILE_BOOT_MSG" --text ":SHOW_BOOT_MSG_TEXT:" --browse $FILE_BOOT_MSG
  4189.   else
  4190.     Error "$FILE_BOOT_MSG ; :ERR_FILE_NOT_FOUND:"
  4191.   fi
  4192. }
  4193.  
  4194.  
  4195. # libLSTdisk - disk handling library shared between several scripts
  4196. #
  4197. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  4198. #
  4199.  
  4200. # List_PARTITION ( [TYPE] )
  4201. #
  4202. # TYPE may be DOS, Linux, Swap, Swapfile, HPFS, Bootmanager, Src, Dest,
  4203. #      the name of a partition or omitted (all partitions)
  4204. # outputs lines in raw format
  4205. #
  4206. List_PARTITION()
  4207. {
  4208.   if [ $# -eq 0 ]; then
  4209.     sysinfo --box --partition
  4210.   else
  4211.     case $1 in
  4212.     DOS|Linux|Dest|Src|HPFS|Swap|Swapfile|Bootmanager)
  4213.       sysinfo --box -C $1 --partition
  4214.       ;;
  4215.     DestSorted)
  4216.       sysinfo --box -C Linux --partition
  4217.       sysinfo --box -C DOS --partition
  4218.       ;;
  4219.     *)
  4220.       sysinfo --box -P $1 --partition
  4221.       ;;
  4222.     esac
  4223.   fi
  4224. }
  4225.  
  4226. # Build_PARTITION ( [--exclude FILE] [TYPE] )
  4227. #
  4228. # TYPE may be DOS, Linux, Swap, Swapfile, HPFS, Bootmanager, Src, Dest,
  4229. #      the name of a partition or omitted (all partitions)
  4230. # outputs lines in menu-item format and adds extra input possibility
  4231. #
  4232. Build_PARTITION()
  4233. {
  4234.   local exclude_file=
  4235.  
  4236.   if [ $# -gt 1 -a "$1" = '--exclude' ]; then
  4237.     exclude_file="$2"
  4238.     shift 2
  4239.   fi
  4240.  
  4241.   Debug "Building partition-list with argument <$1>"
  4242.   if [ -n "$exclude_file" -a -s "$exclude_file" ]; then
  4243.     Debug "Respecting exclude file $exclude_file:"
  4244.     Debug -c cat $exclude_file
  4245.     sed 's/$/ /' $exclude_file > $exclude_file.tmp
  4246.     List_PARTITION $1 | fgrep -vf $exclude_file.tmp
  4247.     rm -f $exclude_file.tmp
  4248.   else
  4249.     Debug "No or empty exclude file specified"
  4250.     List_PARTITION $1
  4251.   fi
  4252.   Is_Expert && echo "\"other\" \":DEVICE_DIRECT:\" \\" 
  4253.   return 0
  4254. }
  4255.  
  4256. Build_HARDDISK_DEV()
  4257. {
  4258.   sysinfo --box --disk
  4259. }
  4260.  
  4261.  
  4262. Menu_Config_Swap()
  4263. {
  4264.   local swapdir=/swap
  4265.   local swapfile=swapfile
  4266.   local swapdev=
  4267.   local swaptype=swap
  4268.   local swapsize=
  4269.   local partid=
  4270.   local defval=
  4271.  
  4272.   defval="`get_val CONF_PARTITIONS_SWAP | cut -d' ' -f 1`"
  4273.   if [ -z "$defval" ]; then
  4274.       defval="`sysinfo --tag -C Swap --partition | sed -n '1p'`"
  4275.   fi
  4276.  
  4277.   while [ 1 ]; do
  4278.     # FIXME: enable swapfile-option
  4279.     Choose --none --menutitle ":CHOOSE_PARTITION_SWAP_MENUTITLE:" --build "Build_PARTITION Swap" SWAP $defval || return 1
  4280.     swapdev="$ANSWER"
  4281.     if [ -z "$ANSWER" ]; then return 0 ; fi
  4282.     partid="`Get_Partition_Info --id $swapdev`"
  4283.     case $partid in
  4284.     1|4|6|11|12|14)
  4285.     swaptype=umsdos
  4286.     ;;
  4287.     130)
  4288.     swaptype=swap
  4289.     swapsize="`Get_Partition_Info --size $swapdev`"
  4290.     ;;
  4291.     131)
  4292.     swaptype=ext2
  4293.     ;;
  4294.     esac
  4295.     case $swaptype in 
  4296.     swap)
  4297.     swapoff $swapdev > /dev/null 2>&1
  4298.     Info ":INFO_SWAP_INITIALIZING:"
  4299.     mkswap $swapdev | Debug -p || continue
  4300.     Info ":INFO_SWAP_ACTIVATING:"
  4301.     sync
  4302.     sync
  4303.     sync
  4304.     sync
  4305.     sleep 3
  4306.     swapon $swapdev || continue
  4307.     if [ -d $DIR_TARGET/etc ]; then
  4308.       echo "$swapdev    none    swap defaults 0 0" >> $DIR_TARGET/$FILE_ETC_FSTAB
  4309.     else
  4310.       echo "$swapdev" > $FILE_SWAP_SEL
  4311.     fi
  4312.     return 0
  4313.     ;;
  4314.     umsdos|ext2)
  4315.     mkdir -p $swapdir
  4316.     Do_Mount -t $swaptype $swapdev $swapdir || continue
  4317.     if [ "$swaptype" = "umsdos" ]; then
  4318.       mkdir -p $swapdir/linux
  4319.       swapfile=linux/swapfile
  4320.     fi
  4321.     if [ -f $swapdir/$swapfile ]; then
  4322.       swapsize="`filesize $swapdir/$swapfile`"
  4323.       swapsize="`do_calc $swapsize / 1024`"
  4324.       dummy=":PARTITION: $swapdev ; :FILE: $swapfile ; :SIZE: ${swapsize}kB ; "
  4325.       Ask_Bool --pretext "$dummy" SWAP_FILE j || continue
  4326.       if [ "$ANSWER" = "1" ]; then
  4327.         rm -f $swapdir/$swapfile
  4328.       fi
  4329.     fi
  4330.     if [ ! -f $swapdir/$swapfile ]; then
  4331.       swapsize="`df /swap | fgrep $swapdev | cut -c 37-45`"
  4332.       if [ $swapsize -gt 8192 ]; then
  4333.         swapsize=8192
  4334.       elif [ $swapsize -gt 4096 ]; then
  4335.         swapsize=4096
  4336.       else
  4337.         Msg ":WARN_NO_SPACE_FOR_SWAPFILE:"
  4338.         continue
  4339.       fi
  4340.     fi
  4341.     ;;
  4342.     esac
  4343.     Info ":INFO_SWAP_INITIALIZING:"
  4344.     if [ ! -f $swapdir/$swapfile ]; then
  4345.     dd if=/dev/zero of=$swapdir/$swapfile bs=1k count=$swapsize || continue
  4346.     sync
  4347.     fi
  4348.     mkswap $swapdir/$swapfile $swapsize || continue
  4349.     Info ":INFO_SWAP_ACTIVATING:"
  4350.     sync
  4351.     sync
  4352.     sync
  4353.     sync
  4354.     sleep 3
  4355.     swapon $swapdir/$swapfile || continue
  4356.     if [ -d $DIR_TARGET/etc ]; then
  4357.       echo "$swapdir/$swapfile    none    swap defaults 0 0" >> $DIR_TARGET/$FILE_ETC_FSTAB
  4358.     fi
  4359.     # do we have less than 12 MB and no swap enabled?
  4360.     if [ `filesize /proc/kcore` -lt 12582912 -a \
  4361.     "`sysinfo --swap --var 2>&1 >/dev/null | cut -d':' -f 2`" -eq 0 ]; then
  4362.     echo "NOT_ENOUGH_RAM" >> $FILE_TMP_ERR
  4363.     Error2 NOT_ENOUGH_RAM
  4364.     # do not let them proceed as it won't work anyway
  4365.     continue
  4366.     fi
  4367.     return 0
  4368.   done
  4369. }
  4370.  
  4371. # test harddisk geometry
  4372. #
  4373. Check_Disk_Geometry()
  4374. {
  4375.     local f_name=Check_Disk_Geometry
  4376.     local f_args=1 # (hardisk) ->
  4377.     local harddisk=
  4378.     local diskname=
  4379.     local geometry=
  4380.     local cylinders=
  4381.     local heads=
  4382.     local sectors=
  4383.     local warning=
  4384.  
  4385.     Check_Args $f_name $f_args $# "$@" || return 255
  4386.     harddisk=$1
  4387.     diskname="`echo $harddisk | sed 's/^\/dev\///'`"
  4388.     geometry="`Get_Val CONF_DISK_GEO_$diskname`" 2> /dev/null
  4389.     if [ -z "$geometry" ]; then
  4390.         geometry="`sysinfo --var --disk $harddisk 2>&1 >/dev/null | cut -d: -f 3,4,5 `"
  4391.         IFS=':' read cylinders heads sectors << EOF
  4392. $geometry
  4393. EOF
  4394.     else
  4395.         read cylinders heads sectors << EOF
  4396. $geometry
  4397. EOF
  4398.     fi
  4399.  
  4400.     # check for invalid number of cylinders and warn if > 1024
  4401.     if [ -z "$cylinders" -o $cylinders -le 0 ]; then
  4402.         warning=INVALID_GEOMETRY
  4403.     else
  4404.         if [ $cylinders -gt 1024 ]; then
  4405.             warning=MANY_CYLINDERS
  4406.         fi
  4407.     fi
  4408.  
  4409.     # check for invalid number of heads
  4410.     if [ -z "$heads" -o $heads -gt 255 -o $heads -le 0 ]; then
  4411.         warning=INVALID_GEOMETRY
  4412.     fi
  4413.  
  4414.     # check for invalid number of sectors
  4415.     if [ -z "$sectors" -o $sectors -gt 63 -o $sectors -le 0 ]; then
  4416.         warning=INVALID_GEOMETRY
  4417.     fi
  4418.     if [ -n "$warning" ]; then
  4419.         Warn2 $warning
  4420.         return 1
  4421.     fi
  4422.     return 0
  4423. }
  4424.  
  4425. Check_Mount_Partition()
  4426. {
  4427.     local f_name=Check_Mount_Partition
  4428.     local f_args=1 # (partition) -> ERROR, STATUS
  4429.     local busydir=
  4430.  
  4431.     Check_Args $f_name $f_args $# "$@" || return 255
  4432.     Check_Partition_Valid $1 || return 1
  4433.     mount | cut -d' ' -f 1 | fgrep -x "$1" > /dev/null 2>&1 
  4434.     if [ $? -ne 0 ]; then
  4435.         ERROR="$1 ; :ERR_PARTITION_NOT_MOUNTED:"
  4436.         return 1 
  4437.     else
  4438.         busydir="`mount | fgrep "$1 on" | cut -d' ' -f 3`"
  4439.         if [ -n "$busydir" ]; then
  4440.             busydir="(${busydir})"
  4441.         fi
  4442.         STATUS="$1 $busydir ; :ERR_PARTITION_ALREADY_MOUNTED:"
  4443.         return 0
  4444.     fi
  4445. }
  4446.  
  4447. Check_Directory()
  4448. {
  4449.     local f_name=Check_Directory
  4450.     local f_args=1 # (directory) -> ERROR
  4451.  
  4452.     Check_Args $f_name $f_args $# "$@" || return 255
  4453.     if [ -d $1 ]; then
  4454.         return 0
  4455.     else
  4456.         ERROR="$1 ; :ERR_DIRECTORY_INVALID:"
  4457.         return 1
  4458.     fi
  4459. }
  4460.  
  4461. # checks if directory is mountable and if false sets STATUS to device
  4462. # and ERROR to an error message
  4463. #
  4464. Check_Directory_Busy()
  4465. {
  4466.     local f_name=Check_Directory_Busy
  4467.     local f_args=1 # (directory) -> STATUS, ERROR
  4468.     export STATUS=
  4469.     export ERROR=
  4470.  
  4471.     Check_Args $f_name $f_args $# "$@" || return 255
  4472.     Check_Directory $1 || return 1
  4473.     mount | cut -d' ' -f 3 | fgrep -x "$1" > /dev/null 2>&1 
  4474.     if [ $? -eq 0 ]; then
  4475.         STATUS="`mount | fgrep "on $1" | cut -d' ' -f 1`"
  4476.         Debug "directory $1 is busy because $STATUS is mounted"
  4477.         ERROR="$1 ; :ERR_DIRECTORY_BUSY:"
  4478.         return  0
  4479.     fi
  4480.     Debug "directory $1 is not busy"
  4481.     return 1
  4482. }
  4483.  
  4484. # checks if a device is already mounted and if true sets STATUS to directory
  4485. # and ERROR to an error message
  4486. #
  4487. Check_Device_Mounted()
  4488. {
  4489.     local f_name=Check_Device_Mounted
  4490.     local f_args=1 # (device) -> STATUS, ERROR
  4491.     export STATUS=
  4492.     export ERROR=
  4493.  
  4494.     Check_Args $f_name $f_args $# "$@" || return 255
  4495.     # FIXME handle devices too (as NFS-Paths), not only partitions
  4496.     mount | cut -d' ' -f 1 | fgrep -x "$1" >/dev/null 2>&1 
  4497.     if [ $? -eq 0 ]; then
  4498.         STATUS="`mount | fgrep "$1 on" | cut -d' ' -f 3`"
  4499.         Debug "device $1 is already mounted on $STATUS"
  4500.         ERROR="$1 ; :ERR_PARTITION_ALREADY_MOUNTED:"
  4501.         return 0
  4502.     fi
  4503.     Debug "device $1 is not mounted"
  4504.     return 1
  4505. }
  4506.  
  4507. # checks if a partition is a primary partition and if false sets
  4508. # ERROR to an error message
  4509. #
  4510. Check_Partiton_Primary()
  4511. {
  4512.     local f_name=Check_Partition_Primary
  4513.     local f_args=1 # (partition) -> ERROR
  4514.     export ERROR=
  4515.  
  4516.     Check_Args $f_name $f_args $# "$@" || return 255
  4517.     Check_Partition_Valid $1 || return 1
  4518.     if [ `echo $1 | cut -c 9-` -lt 5 ]; then
  4519.         if [ `Get_Partition_Info --id $1` -ne 5 ]; then
  4520.             return 0
  4521.         fi
  4522.     fi
  4523.     ERROR="$1 ; :ERR_NO_PRIMARY_PARTITION:"
  4524.     return 1
  4525. }
  4526.  
  4527. # checks if a partition is valid and if false sets ERROR to an error message
  4528. #
  4529. Check_Partition_Valid()
  4530. {
  4531.     local f_name=Check_Partition_Valid
  4532.     local f_args=1 # (partition) -> ERROR
  4533.     export ERROR=
  4534.  
  4535.     # Debug "Check_Partition_Valid: $@"
  4536.     Check_Args $f_name $f_args $# "$@" || return 255
  4537.     if [ ! -b $1 ]; then
  4538.         ERROR="$1 ; :ERR_INVALID_BLOCK_DEVICE:"
  4539.         return 1
  4540.     fi
  4541.     dummy="`sysinfo -P $1 --partition --var 2>&1 >/dev/null`"
  4542.     if [ -z "$dummy" ]; then
  4543.         ERROR="$1 ; :ERR_PARTITION_NOT_FOUND:"
  4544.         return 1
  4545.     fi
  4546.     return 0
  4547. }
  4548.  
  4549. # Smart mount frontend
  4550. #
  4551. # returns:
  4552. # 0    ok
  4553. # 1    was already mounted
  4554. # 2    could not be mounted 
  4555. # 255    parameter error 
  4556. #
  4557. Do_Mount()
  4558. {
  4559.     local f_name=Do_Mount
  4560.     local f_args=2 # ([--verbose] [--types TYPES] [-t TYPE] [-o OPTIONS]
  4561.             # DEVICE DIRECTORY) -> ERROR
  4562.     local verbose_mode=
  4563.     local mounttype=
  4564.     local mountopt=
  4565.     local mountdev=
  4566.     local mountdir=
  4567.     local mountline=
  4568.     local partid=
  4569.     local dummy=
  4570.     local loop=
  4571.     local mounttypealt="ext2 umsdos msdos minix iso9660 hpfs"
  4572.     export ANSWER=
  4573.  
  4574.     # parse options
  4575.     while [ 1 ]; do
  4576.         if [ $# -gt 1 ]; then
  4577.             case $1 in
  4578.             --types)
  4579.                 mounttypealt="$2"
  4580.                 shift 2
  4581.                 continue;;
  4582.             -t)
  4583.                 mounttype="$2"
  4584.                 mounttypealt=""
  4585.                 shift 2
  4586.                 continue;;
  4587.             -o)
  4588.                 mountopt="$2"
  4589.                 shift 2
  4590.                 continue;;
  4591.             esac
  4592.         fi
  4593.         if [ $# -gt 0 ]; then
  4594.             case $1 in
  4595.             --verbose)
  4596.                 verbose_mode=true
  4597.                 shift 1
  4598.                 continue;;
  4599.             esac
  4600.         fi
  4601.         Check_Args $f_name $f_args $# "$@" || return 255
  4602.         mountdev=$1
  4603.         mountdir=$2
  4604.         shift 2
  4605.         break
  4606.     done
  4607.  
  4608.     if [ -z "$mounttype" ]; then
  4609.         # try to determine mounttype
  4610.         # check for nfs mount
  4611.         if [ -n "`echo $mountdev | sed -n '/:/p'`" ]; then
  4612.             mounttype=nfs
  4613.             mounttypealt=
  4614.             # shift 1 
  4615.         # check for device mount
  4616.         elif [ -n "`echo $mountdev | sed -n '/^\/dev\//p'`" ]; then
  4617.             # check for iso9660 mount (dirty hack)
  4618.             if [ -n "`echo $mountdev | sed -n '/cd/p'`" ]; then
  4619.                 mounttype=iso9660
  4620.                 mountopt="ro"
  4621.             # check for floppy mount (dirty hack)
  4622.             elif [ -n "`echo $mountdev | sed -n '/^\/dev\/fd/p'`" ]; then
  4623.                 mounttype=msdos
  4624.                 mounttypealt="minix umsdos"
  4625.             # check for partition mount (dirty hack)
  4626.             elif [ -n "`echo $mountdev | sed -n '/^\/dev\/[irshx]d/p'`" ]; then
  4627.                 # Get partition id
  4628.                 partid="`Get_Partition_Info --id $mountdev`"
  4629.                 if [ -z "$partid" ]; then
  4630.                     Error "partition-id of $mountdev could not be determined!"
  4631.                     return 1
  4632.                 fi
  4633.                 case $partid in
  4634.                 1|4|6|11|12|14)
  4635.                     mounttype="msdos"
  4636.                     mounttypealt="umsdos"
  4637.                     ;;
  4638.                 7)
  4639.                     mounttype="hpfs"
  4640.                     mounttypealt="msdos umsdos"
  4641.                     ;;
  4642.                 128|129)
  4643.                     mounttype="minix"
  4644.                     mounttypealt="ext2"
  4645.                     ;;
  4646.                 130)
  4647.                     mounttype="swap"
  4648.                     ;;
  4649.                 131)
  4650.                     mounttype="ext2"
  4651.                     mounttypealt="minix ext xiafs"
  4652.                     ;;
  4653.                 *)
  4654.                     Error "unknown partition-id $partid for $mountdev!"
  4655.                     return 2
  4656.                     ;;
  4657.                 esac
  4658.             fi # no partition
  4659.         fi # no device
  4660.     fi # mounttype=""
  4661.  
  4662.     # mount loop
  4663.     rm -f $FILE_TMP_ERR
  4664.     for loop in $mounttype $mounttypealt ; do
  4665.         Do_Load_Driver filesystem $mounttype || continue
  4666.         Check_Device_Mounted $mountdev
  4667.         if [ $? -eq 0 ]; then
  4668.             if [ "$STATUS" = "$mountdir" ]; then
  4669.                 Debug "keep it mounted. Ok"
  4670.                 mount | fgrep "$mountdev on" | cut -d' ' -f 5 > $FILE_TMP_VAL
  4671.                 ANSWER="`cat $FILE_TMP_VAL`"
  4672.                 return 0
  4673.             else
  4674.                 Debug "unmount it."
  4675.                 Do_Umount $mountdev
  4676.             fi
  4677.         fi
  4678.         Check_Directory_Busy $mountdir
  4679.         if [ $? -eq 0 ]; then
  4680.             if [ "$STATUS" = "$mountdev" ]; then
  4681.                 Debug "keep it mounted. Ok"
  4682.                 mount | fgrep "$mountdev on" | cut -d' ' -f 5 > $FILE_TMP_VAL
  4683.                 ANSWER="`cat $FILE_TMP_VAL`"
  4684.                 return 0
  4685.             else
  4686.                 Debug "unmount it."
  4687.                 Do_Umount $mountdir
  4688.             fi
  4689.         fi
  4690.         dummy=
  4691.         if [ -n "$mountopt" ]; then
  4692.             dummy="-o $mountopt"
  4693.         fi
  4694.         rm -f /etc/mtab~
  4695.         if [ "$loop" = "nfs" ]; then
  4696.             Info ":INFO_TRYING_NFS_MOUNT:"
  4697.         fi
  4698.         Debug "Trying mount -t $loop $dummy $mountdev $mountdir"
  4699.         # Do_Clear_Screen
  4700.         # echo "trying: mount -t $loop $dummy $mountdev $mountdir"
  4701.         mount -t $loop $dummy $mountdev $mountdir > $FILE_TMP_ERR.tmp 2>&1
  4702.         retval=$?
  4703.         if [ $retval -eq 0 ]; then
  4704.             # Success
  4705.             Debug "Success!"
  4706.             # if [ -n "$verbose_mode" ]; then
  4707.                 # Info ":PARTITION: = $mountdev ; :DIRECTORY: = $mountdir ; :FILESYTEM_TYPE: = $mounttype ; :INFO_MOUNT_SUCCESS:"
  4708.                 # sleep 1
  4709.             # fi
  4710.             ANSWER="$loop"
  4711.             return 0
  4712.         else
  4713.             # Failure
  4714.             Debug "Failed!"
  4715.             Debug -c cat $FILE_TMP_ERR.tmp
  4716.             cat $FILE_TMP_ERR.tmp >> $FILE_TMP_ERR
  4717.         fi
  4718.     done
  4719.     # if [ -n "$verbose_mode" ]; then
  4720.         Error2 MOUNT_FAILED
  4721.     # fi
  4722.     return 2
  4723. }
  4724.  
  4725. Do_Umount()
  4726. {
  4727.     local f_name=Do_Umount
  4728.     local f_args=1 # (device/nfs-path/directory) ->
  4729.  
  4730.     Check_Args $f_name $f_args $# "$@" || return 255
  4731.  
  4732.     while [ 1 ]; do
  4733.         rm -f /etc/mtab~
  4734.         Debug "unmounting $1 ..."
  4735.         umount $1 >$FILE_TMP_ERR 2>&1
  4736.         if [ $? -ne 0 ]; then
  4737.             fgrep "not mounted" $FILE_TMP_ERR >/dev/null && return 0
  4738.             fgrep "not found" $FILE_TMP_ERR >/dev/null && return 0
  4739.             Error2 UMOUNT_FAILED || return 1
  4740.         else
  4741.             return 0
  4742.         fi
  4743.     done
  4744. }
  4745.  
  4746. Get_Filesystem_Usage()
  4747. {
  4748.   local cut="1-10,18-28,37-45,47-53,56-"
  4749.  
  4750.   # CHECK-ray: 'used' right-aligns with number, not '%', thus
  4751.   #   extending space between 'used' and 'mount' ...
  4752.   echo "Filesystem   size(kB) free(kB)  used  mount point"
  4753.   if [ "$1" = "--install" ]; then
  4754.     shift
  4755.     if [ "$DIR_TARGET" != "/" ]; then
  4756.       # display ONLY target devices on their future mount points 
  4757.       df | cut -c $cut | \
  4758.          fgrep -v "Filesystem" | \
  4759.          fgrep '/root' | \
  4760.          sed 's: /root/linux: /:' | \
  4761.          sed 's: /root: /:' | \
  4762.          sed 's://:/:'
  4763.     else
  4764.       df -t ext2 | cut -c $cut | \
  4765.          fgrep -v "Filesystem"
  4766.     fi
  4767.   elif [ -e "$1" ]; then
  4768.     df $1 | cut -c $cut | \
  4769.        fgrep -v "Filesystem" 
  4770.   else
  4771.     df | cut -c $cut | \
  4772.        fgrep -v "Filesystem"  
  4773.   fi
  4774. }
  4775.  
  4776. # Get_Partition_Info ( { --boot, --size, --id, --type} PARTITION )
  4777. #
  4778. # return:
  4779. # 0    ok
  4780. # 1    no partition specified
  4781. # 2    partition not found
  4782. # 3    no value available
  4783. #
  4784. Get_Partition_Info()
  4785. {
  4786.     FUNC_NAME=Get_Partition_Info
  4787.     local field=
  4788.  
  4789.     # Debug "Get_Partition_Info: $@"
  4790.     if [ $# -gt 0 ]; then
  4791.         if [ "$1" = '--boot' ]; then
  4792.             field=3
  4793.             shift 1
  4794.         elif [ "$1" = '--size' ]; then
  4795.             field=4
  4796.             shift 1
  4797.         elif [ "$1" = '--id' ]; then
  4798.             field=5
  4799.             shift 1
  4800.         elif [ "$1" = '--type' ]; then
  4801.             field=6
  4802.             shift 1
  4803.         else
  4804.             field=
  4805.         fi
  4806.     fi
  4807.  
  4808.     Check_Partition_Valid $1 || return 1
  4809.     dummy="`sysinfo -P $1 --partition --var 2>&1 >/dev/null | cut -d':' -f $field`"
  4810.  
  4811.     if [ -z "$dummy" ]; then
  4812.         Error "no value available for field $field"
  4813.         return 3
  4814.     fi
  4815.     # Debug "Get_Partition_Info: result = <$dummy>"
  4816.     echo "$dummy"
  4817.     return 0
  4818. }
  4819.  
  4820.  
  4821. Menu_Harddisk_Parameters()
  4822. {
  4823.     local harddisk=
  4824.     local diskname=
  4825.     local cylinders=
  4826.     local heads=
  4827.     local sectors=
  4828.     local geometry=
  4829.  
  4830.     if [ $# -ne 1 ]; then
  4831.         Panic ":ERR_WRONG_NUM_OF_ARGS:"
  4832.     fi
  4833.  
  4834.     harddisk=$1
  4835.     diskname="`echo $harddisk | sed 's/^\/dev\///'`"
  4836.  
  4837.     geometry="`Get_Val CONF_DISK_GEOMETRY_$diskname`" 2> /dev/null
  4838.     if [ -z "$geometry" ]; then
  4839.         geometry="`sysinfo --var --disk $harddisk 2>&1 >/dev/null | cut -d: -f 3,4,5 `"
  4840.         IFS=':' read cylinders heads sectors << EOF
  4841. $geometry
  4842. EOF
  4843.     else
  4844.         read cylinders heads sectors << EOF
  4845. $geometry
  4846. EOF
  4847.     fi
  4848.  
  4849.     while [ 1 ]; do
  4850.         # Ask_Bool --pretext ":HARDDISK: $harddisk ; CHS=$cylinders/$heads/$sectors ; " HARDDISK_PARAMETERS || return 1
  4851.         Ask_Bool --text ":HARDDISK: $harddisk ; CHS=$cylinders/$heads/$sectors ; :ASK_HARDDISK_PARAMETERS_HELP:" HARDDISK_PARAMETERS || return 1
  4852.         case $ANSWER in
  4853.         0)
  4854.             break
  4855.             ;;
  4856.         1)
  4857.             # Cylinders
  4858.             Ask_String CYLINDERS $cylinders || return 1
  4859.             cylinders="$ANSWER"
  4860.  
  4861.             # Heads
  4862.             Ask_String HEADS $heads || return 1
  4863.             heads="$ANSWER"
  4864.             
  4865.             # Sectors
  4866.             Ask_String SECTORS $sectors || return 1
  4867.             sectors="$ANSWER"
  4868.             ;;
  4869.         esac
  4870.     done
  4871.     Do_Store CONF_DISK_GEOMETRY_$diskname "$heads $sectors $cylinders"
  4872. }
  4873.  
  4874. # returns 0 on mke2fs success
  4875. # returns 1 on error or abort
  4876. # returns 2 of mke2fs was skipped
  4877. #
  4878. Menu_Call_Mke2fs()
  4879. {
  4880.     local badblocks_flag=
  4881.     local reserved_flag=
  4882.     local inodes_flag=
  4883.     local partid=
  4884.  
  4885.     # FIXME. Set Name in text
  4886.     # test for type Linux native
  4887.     partid="`Get_Partition_Info --id $1`"
  4888.     if [ -n "$partid" -a "$partid" != "131" ]; then
  4889.         Error "Partition $1 ; :ERR_NO_LINUX_PARTITION:"
  4890.         return 1
  4891.     fi
  4892.  
  4893.     # test whether it's mounted
  4894.     mount | fgrep "$1 " >/dev/null 2>&1
  4895.     if [ $? -eq 0 ]; then
  4896.         Error "Partition $1 ; :ERR_PARTITION_ALREADY_MOUNTED:"
  4897.         return 1
  4898.     fi
  4899.  
  4900.     Ask_Bool --pretext "Partition $1 ; " CALL_MKE2FS || return 1
  4901.     if [ "$ANSWER" = "1" ]; then return 2 ; fi
  4902.     Is_Expert
  4903.     if [ $? -eq 0 ]; then
  4904.         while [ 1 ]; do
  4905.             # Ask_String MKE2FS_INODES "4096"
  4906.             Ask_String --pretext "Partition $1 ; " MKE2FS_INODES "4096" || return 1
  4907.             if [ -n "$ANSWER" ]; then
  4908.                 if [ $ANSWER -gt 1023 ]; then break ; fi
  4909.             fi
  4910.             Error ":ERR_INVALID_ANSWER:" || return 1
  4911.         done
  4912.         inodes_flag="-i $ANSWER"
  4913.         while [ 1 ]; do
  4914.             # Ask_String MKE2FS_RESERVED "5"
  4915.             Ask_String --pretext "Partition $1 ; " MKE2FS_RESERVED "5" || return 1
  4916.             if [ -n "$ANSWER" ]; then
  4917.                 if [ 0 -le $ANSWER -a $ANSWER -lt 100 ]; then break ; fi
  4918.             fi
  4919.             Error ":ERR_INVALID_ANSWER:"
  4920.         done
  4921.         reserved_flag="-m $ANSWER"
  4922.     fi
  4923.     badblocks_flag="-c"
  4924.     Ask_Bool --pretext "Partition $1 ; " MKE2FS_BADBLOCKS n || return 1
  4925.     if [ "$ANSWER" = "1" ]; then
  4926.         badblocks_flag=
  4927.     fi
  4928.     Do_Clear_Screen
  4929.     prep_use PREPARE || return 1
  4930.     $DO_SIMULATE mke2fs $badblocks_flag $reserved_flag $inodes_flag $1 2>&1 || return 1
  4931.     return 0
  4932. }
  4933.  
  4934. Menu_Call_Fdisk()
  4935. {
  4936.   local diskname
  4937.   local mbrfile
  4938.   local crc1
  4939.   local crc2
  4940.   local fdisk_retval
  4941.  
  4942.   if [ $# -ne 1 ]; then
  4943.     Panic ":ERR_WRONG_NUM_OF_ARGS:"
  4944.   fi
  4945.  
  4946.   Check_Disk_Geometry $1
  4947.   if [ $? -ne 0 ]; then
  4948.     Menu_Harddisk_Parameters $1
  4949.   fi
  4950.  
  4951.   diskname="`echo $1 | sed 's/^\/dev\///'`"
  4952.   mbrfile=$DIR_LST_TMP/mbr${diskname}
  4953.  
  4954.   # safe boot sector before calling fdisk
  4955.   dd if=$1 of=$mbrfile bs=512 count=1 >/dev/null 2>&1
  4956.   gzip -f $mbrfile
  4957.  
  4958.   $CMD_BOX --help ":MENU_CALL_FDISK_HELP:" \
  4959. --title ":MENU_CALL_FDISK_TITLE:" \
  4960. --bool ":MENU_CALL_FDISK_TEXT:" 2> $FILE_TMP_ANSWER || return 1
  4961.   ANSWER="`cat $FILE_TMP_ANSWER`"
  4962.   if [ "$ANSWER" != "0" ]; then return 1 ; fi
  4963.   Do_Clear_Screen
  4964.   if [ -f /usr/doc/LST/use-fdisk.gz ]; then
  4965.     zcat /usr/doc/LST/use-fdisk.gz
  4966.   fi
  4967.   fdisk "$1"
  4968.   fdisk_retval="$?"
  4969.  
  4970.   # safe boot sector after calling fdisk
  4971.   dd if=$1 of=$mbrfile.new bs=512 count=1 >/dev/null 2>&1
  4972.   gzip -f $mbrfile.new
  4973.  
  4974.   # compare by gzip CRC (no space for cmp or diff on rootdisk)
  4975.   crc1="`gzip -vl $mbrfile.gz | fgrep mbr${diskname} | cut -c 7-14`"
  4976.   crc2="`gzip -vl $mbrfile.new.gz | fgrep mbr${diskname}.new | cut -c 7-14`"
  4977.   if [ "$crc1" != "$crc2" ]; then
  4978.     Warn ":WARN_PARTITION_TABLE_MODIFIED:"
  4979.     if [ $fdisk_retval != 0 ]; then
  4980.       export NEED_TO_REBOOT=true
  4981.     else
  4982.       export NEED_TO_REBOOT=possible
  4983.     fi
  4984.   fi
  4985.   rm -f $mbrfile.gz $mbrfile.new.gz
  4986.   return 0
  4987. }
  4988.  
  4989.  
  4990. Show_Filesystem_Usage()
  4991. {
  4992.     Get_Filesystem_Usage $1 > $FILE_TMP_VAL
  4993.     Browse2 $FILE_TMP_VAL FILESYSTEM_USAGE
  4994. }
  4995.  
  4996.  
  4997. # libLSTfirst - first install library shared between several scripts
  4998. #
  4999. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  5000. #
  5001.  
  5002. Recover_COL11_Strings()
  5003. {
  5004.     local my_lang="`Get_Val CONF_LST_LANG`"
  5005.  
  5006.     case $my_lang in
  5007.     de|us)
  5008.         ;;
  5009.     *)
  5010.         my_lang=us
  5011.         set_val CONF_LST_LANG us
  5012.         ;;
  5013.     esac
  5014.  
  5015.     Debug "trying to recover libLSTtext ($my_lang) from COL 1.1 CD"
  5016.     zcat /mnt/col/launch/dos/initrd.gz > /dev/ram2
  5017.     mkdir -p /ram2
  5018.     mount -t ext2 /dev/ram2 /ram2
  5019.     # filter out my_lang
  5020.     zcat /ram2/usr/lib/LST/libLSTtext.gz | sed "{
  5021.         s/^${my_lang}-x> //
  5022.         s/^x-x> //
  5023.         /^..-x> /d
  5024.         }" > /ram2/usr/lib/LST/libLSTtext
  5025.     Debug "merging with source file /ram2/usr/lib/LST/libLSTtext"
  5026.     Do_Merge_libLSTtext /usr/lib/LST/libLSTtext /ram2/usr/lib/LST/libLSTtext
  5027.     Debug "merging done"
  5028.     if [ -f /bin/freeramdisk.gz ]; then
  5029.         gunzip /bin/freeramdisk
  5030.     fi
  5031.     if [ -f /bin/freeramdisk ]; then
  5032.         freeramdisk /dev/ram2
  5033.     fi
  5034.     umount /ram2
  5035.     rm -fr /ram2
  5036. }
  5037.  
  5038. Do_Read_Source()
  5039. {
  5040.   local my_lang="`Get_Val CONF_LST_LANG`"
  5041.  
  5042.   Debug "CONF_LST_LANG=$my_lang"
  5043.  
  5044.   Info ":INFO_WAIT:"
  5045.   # check if we have pkg infos in the install tree
  5046.   for i in meta.db pkgs.all pkgs.db pkgs.idx pkgs.min pkgs.rec ; do
  5047.     if [ -f $DIR_DATA/$i ]; then
  5048.       Debug "using source file $DIR_DATA/$i"
  5049.       cp -a $DIR_DATA/$i /usr/lib/LST/$i
  5050.     fi
  5051.   done
  5052.   if [ -f $DIR_DATA/$my_lang/pkgs.idx ]; then
  5053.     Debug "using source file $DIR_DATA/$my_lang/pkgs.idx"
  5054.     cp -a $DIR_DATA/$my_lang/pkgs.idx /usr/lib/LST/pkgs.idx
  5055.   elif [ -f $DIR_DATA/us/pkgs.idx ]; then
  5056.     # if language specific not available use english
  5057.     Debug "using source file $DIR_DATA/us/pkgs.idx"
  5058.     cp -a $DIR_DATA/us/pkgs.idx /usr/lib/LST/pkgs.idx
  5059.   fi
  5060.   if [ "$INSTALL_MODE" = "OpenLinux" ]; then
  5061.     if [ -f $DIR_DATA/$my_lang/libLSTtext ]; then
  5062.       Debug "merging with source file $DIR_DATA/$my_lang/libLSTtext"
  5063.       Do_Merge_libLSTtext /usr/lib/LST/libLSTtext $DIR_DATA/$my_lang/libLSTtext
  5064.       Debug "merging done"
  5065.     elif [ -f $DIR_DATA/us/libLSTtext ]; then
  5066.       # if language specific not available use english
  5067.       Debug "merging with source file $DIR_DATA/us/libLSTtext"
  5068.       Do_Merge_libLSTtext /usr/lib/LST/libLSTtext $DIR_DATA/us/libLSTtext
  5069.       Debug "merging done"
  5070.     # NT does not properly handle TRANS.TBL files
  5071.     elif [ -f $DIR_DATA/$my_lang/liblstte ]; then
  5072.       Debug "merging with source file $DIR_DATA/$my_lang/liblstte"
  5073.       Do_Merge_libLSTtext /usr/lib/LST/libLSTtext $DIR_DATA/$my_lang/liblstte
  5074.       Debug "merging done"
  5075.     # NT does not properly handle TRANS.TBL files
  5076.     elif [ -f $DIR_DATA/us/liblstte ]; then
  5077.       Debug "merging with source file $DIR_DATA/us/liblstte"
  5078.       Do_Merge_libLSTtext /usr/lib/LST/libLSTtext $DIR_DATA/us/liblstte
  5079.       Debug "merging done"
  5080.     fi
  5081.   fi
  5082.   # this is to still support COL 1.1 installs as good as possible
  5083.   if [ -f /mnt/col/install/RPMS/lisa-2.3-7.i386.rpm ]; then
  5084.     Recover_COL11_Strings
  5085.   fi
  5086.   # check if we have private pkg infos in the install tree
  5087.   for i in meta.db pkgs.db pkgs.idx pkgs.sel ; do
  5088.     if [ -f $DIR_DATA/private/$i ]; then
  5089.       Debug "using source file $DIR_DATA/private/$i"
  5090.       cp -a $DIR_DATA/private/$i /usr/lib/LST/$i
  5091.     fi
  5092.   done
  5093.   for i in cpio rpm rpmextr rpmq ; do
  5094.     if [ -f $DIR_BIN/$i ]; then
  5095.       Debug "using source file $DIR_BIN/$i"
  5096.       ln -sf $DIR_BIN/$i /bin/$i
  5097.     else
  5098.       # this is to support CND 1.0 install
  5099.       # and to copy cpio, rpmextr and rpmq from floppy
  5100.       if [ ! -f /bin/$i ]; then
  5101.     if [ -f /floppy/bin/$i.gz ]; then
  5102.       cp -a /floppy/bin/$i.gz /bin/$i.gz
  5103.       gunzip /bin/$i.gz
  5104.     fi
  5105.       fi
  5106.     fi
  5107.   done
  5108.   if [ -f $DIR_BIN/rpm-3.0.3 ]; then
  5109.     Debug "switching to use rpm-3.0.3 from $DIR_BIN/rpm-3.0.3"
  5110.     rm -f /bin/rpm
  5111.     ln -sf $DIR_BIN/rpm-3.0.3 /bin/rpm
  5112.   fi
  5113.   # this is to support CND 1.0 install
  5114.   if [ ! -f /bin/rpm ]; then
  5115.     ln -s rpmq /bin/rpm
  5116.   fi
  5117.   # this is to check whether we have execute permissions
  5118.   for i in cpio rpm rpmextr ; do
  5119.     if [ ! -x /bin/$i ]; then
  5120.       chmod +x /bin/$i > /dev/null 2>&1
  5121.     fi
  5122.     if [ ! -x /bin/$i ]; then
  5123.       Msg "/bin/$i ; :ERR_MISSING_EXEC_PERMISSIONS:"
  5124.     fi
  5125.   done
  5126.   prep_use SELECT
  5127. }
  5128.  
  5129.  
  5130. # converts decimal number to it's hexadecimal representation
  5131. # on failure sets ERROR to an error message
  5132. #
  5133. Dec2Hex()
  5134. {
  5135.   # printf "%02x\n" $1
  5136.   # this would be too easy (and costs approx. 6k on floppy)...
  5137.   # so let's do it the HARD WAY(TM) !-)
  5138.   local n1=`do_calc $1 / 16`
  5139.   local t1=`do_calc $n1 \* 16`
  5140.   local n2=`do_calc $1 - $t1`
  5141.   local i=
  5142.   local r=""
  5143.   export ERROR=
  5144.   
  5145.   if [ "$1" -gt 255 ]; then
  5146.     ERROR="Dec2Hex: number too big ($1 > 255)"
  5147.     return 1
  5148.   fi
  5149.  
  5150.   if [ $n1 -eq 0 ]; then
  5151.       n1=0
  5152.   fi
  5153.  
  5154.   for i in $n1 $n2; do
  5155.     if [ $i -lt 10 ]; then
  5156.       r="${r}$i"
  5157.     else
  5158.       case "$i" in
  5159.         10) r="${r}a" ;;
  5160.         11) r="${r}b" ;;
  5161.         12) r="${r}c" ;;
  5162.         13) r="${r}d" ;;
  5163.         14) r="${r}e" ;;
  5164.         15) r="${r}f" ;;
  5165.     *) ERROR="Dec2Hex: illegal condition: remainder < 15"; return 1;;
  5166.       esac
  5167.     fi
  5168.   done
  5169.   
  5170.   echo "$r"
  5171.   return 0
  5172. }
  5173.  
  5174. Set_Real_Root()
  5175. {
  5176.   local root_dev=
  5177.   local driver=
  5178.   local disk=
  5179.   local base=
  5180.   local partition=
  5181.   local major=
  5182.   local minor=
  5183.   local high=
  5184.   local low=
  5185.   local bios_id=
  5186.  
  5187.   root_dev="`echo $1 | sed 's/^\/dev\///'`"
  5188.   driver="`echo $root_dev | cut -c 1-2`"
  5189.   if [ "$driver" = "rd" ]; then
  5190.     driver="`echo $root_dev | cut -c 1-5`"
  5191.     disk="`echo $root_dev | cut -c 7-7`"
  5192.     partition="`echo $root_dev | cut -c 9-`"
  5193.     base=8
  5194.   elif [ "$driver" = "id" ]; then
  5195.     driver="`echo $root_dev | cut -c 1-6`"
  5196.     disk="`echo $root_dev | cut -c 8-8`"
  5197.     partition="`echo $root_dev | cut -c 10-`"
  5198.     base=8
  5199.   else
  5200.     disk="`echo $root_dev | cut -c 3-3`"
  5201.     partition="`echo $root_dev | cut -c 4-`"
  5202.     base=64
  5203.   fi
  5204.  
  5205.   case $driver in
  5206.   hd)
  5207.     if [ "$disk" = "a" -o "$disk" = "b" ]; then major=3
  5208.     else major=22
  5209.     fi
  5210.     ;;
  5211.   ida/c0) major=72 ;;
  5212.   rd/c0) major=48 ;;
  5213.   sd)
  5214.     base=16
  5215.     major=8
  5216.     ;;
  5217.   xd) major=13 ;;
  5218.   esac
  5219.  
  5220.   high="`Dec2Hex $major`"
  5221.  
  5222.   case $disk in
  5223.   a|0) minor=0 ;;
  5224.   b|1) minor=1 ;;
  5225.   c|2)
  5226.       if [ "$driver" = "hd" ]; then
  5227.         minor=0
  5228.     else
  5229.         minor=2
  5230.     fi
  5231.     ;;
  5232.   d|3)
  5233.       if [ "$driver" = "hd" ]; then
  5234.         minor=1
  5235.     else
  5236.         minor=3
  5237.     fi
  5238.     ;;
  5239.   e|4) minor=4 ;;
  5240.   f|5) minor=5 ;;
  5241.   g|6) minor=6 ;;
  5242.   h|7) minor=7 ;;
  5243.   esac
  5244.  
  5245.   low="`do_calc $minor \* $base`"
  5246.   low="`do_calc $low \+ $partition`"
  5247.   low="`Dec2Hex $low`"
  5248.  
  5249.   bios_id="0x${high}${low}"
  5250.  
  5251.   Is_Expert
  5252.   if [ $? -eq 0 ]; then
  5253.     Ask_String ROOT_ID "$bios_id" || return 1
  5254.     bios_id="$ANSWER"
  5255.   fi
  5256.  
  5257.   if [ -n "$bios_id" ]; then
  5258.     echo "$bios_id" > /etc/rootdev
  5259.     echo "$bios_id" > /proc/sys/kernel/real-root-dev
  5260.   fi
  5261. }
  5262.  
  5263. Do_Reboot()
  5264. {
  5265.   Info ":INFO_REBOOTING:"
  5266.   sleep 3
  5267.   Do_Clear_Screen
  5268.   reboot
  5269. }
  5270.  
  5271. Menu_Config_Partitioning()
  5272. {
  5273.   local defval
  5274.   local trouble
  5275.  
  5276.   while [ 1 ]; do
  5277.     defval=n
  5278.     trouble=
  5279.  
  5280.     # do we have any target partition at all?
  5281.     if [ -z "`sysinfo -C Dest --notitle --noheader --partition`" ]; then
  5282.       trouble=NO_TARGET_AVAILABLE
  5283.       defval=y
  5284.     fi
  5285.  
  5286.     # do we have less than 12 MB but no swap partition?
  5287.     if [ `filesize /proc/kcore` -lt 12582912 -a \
  5288.     -z "`sysinfo -C Swap --notitle --noheader --partition`" ]; then
  5289.       trouble=NOT_ENOUGH_RAM
  5290.       defval=y
  5291.     fi
  5292.  
  5293.     Ask_Bool CALL_FDISK $defval || return 1
  5294.     if [ "$ANSWER" = "1" ]; then
  5295.       if [ -n "$trouble" ]; then
  5296.     echo "$trouble" >> $FILE_TMP_ERR
  5297.     Error2 $trouble
  5298.     continue
  5299.       fi
  5300.       return 0
  5301.     fi
  5302.  
  5303.     Do_Modify_Partitioning || continue
  5304.     break
  5305.   done
  5306.   return 0
  5307. }
  5308.  
  5309.  
  5310. Do_Modify_Partitioning()
  5311. {
  5312.   local retval=1
  5313.  
  5314.   while [ 1 ]; do
  5315.     while [ 1 ]; do
  5316.       # ask for hard disk    
  5317.       Choose --none --other --build Build_HARDDISK_DEV HARDDISK_DEV || break
  5318.       if [ -z "$ANSWER" ]; then
  5319.         retval=0
  5320.         break
  5321.       fi
  5322.       Menu_Call_Fdisk "$ANSWER" || continue
  5323.     done
  5324.     if [ -n "$NEED_TO_REBOOT" ]; then
  5325.       Ask_Bool NEED_TO_REBOOT || continue
  5326.       if [ "$ANSWER" = "0" ]; then Do_Reboot ; fi
  5327.     fi
  5328.     break
  5329.   done
  5330.   return $retval
  5331. }
  5332.  
  5333. Fix_uucp()
  5334. {
  5335.   local i
  5336.  
  5337.   for i in /var/spool/uucp /var/spool/uucppublic ; do
  5338.     mkdir -p $DIR_TARGET${i}
  5339.     chown uucp.uucp $DIR_TARGET${i}
  5340.     chmod 1777 $DIR_TARGET${i}
  5341.   done
  5342.  
  5343.   i=/var/log/uucp
  5344.  
  5345.   touch $DIR_TARGET${i}
  5346.   chown uucp.uucp $DIR_TARGET${i}
  5347.   if [ -d $DIR_TARGET${i} ]; then
  5348.     chmod 775 $DIR_TARGET${i}
  5349.   else
  5350.     chmod 664 $DIR_TARGET${i}
  5351.   fi
  5352. }
  5353.  
  5354. Fix_sendmail_start()
  5355. {
  5356.   set_val -f /root/etc/sysconfig/daemons/sendmail ONBOOT yes
  5357. }
  5358.  
  5359. Fix_httpd_start()
  5360. {
  5361.   # this fix is for apache-1.1.1-10
  5362.   if [ -d /root/usr/doc/apache-httpd-1.1.1-10 -a \
  5363.       ! -f /root/etc/sysconfig/daemons/httpd ]; then
  5364.     cat << EOD  > /root/etc/sysconfig/daemons/httpd
  5365. IDENT=WWW
  5366. DESCRIPTIVE="WEB server"
  5367. ONBOOT=no
  5368. VARIANT=apache
  5369. EOD
  5370.   fi
  5371.   set_val -f /root/etc/sysconfig/daemons/httpd ONBOOT yes
  5372. }
  5373.  
  5374. Fix_passwd()
  5375. {
  5376.     local nis_magic
  5377.  
  5378.     # grep out root account (with password) and adjust HOME
  5379.     sed -n '/^root:/p' /etc/passwd | sed 's/:\/:/:\/root:/' > /etc/passwd.tmp
  5380.  
  5381.     # append normal passwd (without root account)
  5382.     sed '/^root:/d' $DIR_TARGET/etc/passwd >> /etc/passwd.tmp
  5383.  
  5384.     nis_magic="`sed -n '/^+/p' /etc/passwd.tmp`"
  5385.     if [ -n "$nis_magic" ]; then
  5386.         sed '/^+/d' /etc/passwd.tmp > /etc/passwd.nismagic
  5387.         mv -f /etc/passwd.nismagic /etc/passwd.tmp
  5388.     fi
  5389.  
  5390.     # grep out normal account (with password)
  5391.     if [ -n "$LAST_USER" ]; then
  5392.         sed -n "/^$LAST_USER:/p" /etc/passwd >> /etc/passwd.tmp
  5393.     fi
  5394.     if [ -n "$nis_magic" ]; then
  5395.         echo "$nis_magic" >> /etc/passwd.tmp
  5396.     fi
  5397.  
  5398.     # on COL 2.2 setup does not provide a passwd, so we have to fix ours
  5399.     sed '{
  5400.         /^install/d
  5401.         /^expert/d
  5402.         /^setup/d
  5403.         /^hilfe/d
  5404.         /^help/d
  5405.         s/Nobody:\/:/Nobody:\/:\/bin\/false/
  5406.         }' /etc/passwd.tmp > /etc/passwd.tmp2
  5407.     mv /etc/passwd.tmp2 /etc/passwd.tmp
  5408.  
  5409.     chown root.root /etc/passwd.tmp
  5410.     chmod 644 /etc/passwd.tmp
  5411.     mv /etc/passwd.tmp $DIR_TARGET/etc/passwd
  5412.  
  5413.     # if we are on a COL 1.2 install then switch to shadow passwords
  5414.     if [ "$INSTALL_MODE" = "OpenLinux" -a -x $DIR_TARGET/usr/sbin/pwconv ]; then
  5415.         Debug "calling pwconv to switch to shadow passwords"
  5416.         History_Install "calling pwconv to switch to shadow passwords"
  5417.         ( cd $DIR_TARGET; chroot $DIR_TARGET usr/sbin/pwconv ) > $DIR_TARGET/install/pwconv.error 2>&1
  5418.         # remove empty error logs
  5419.         if [ ! -s $DIR_TARGET/install/pwconv.error ]; then
  5420.             rm -f $DIR_TARGET/install/pwconv.error
  5421.         fi
  5422.     fi
  5423.     return 0
  5424. }
  5425.  
  5426. Menu_First_Install()
  5427. {
  5428.     export INSTALL_STATE=3
  5429.     local disk=
  5430.     local partition=
  5431.     local orig_source=
  5432.     local orig_dev=
  5433.     local orig_mode=
  5434.     local max_state_seen=-1
  5435.  
  5436.     History "`date` $LOGNAME: LISA: first time install (${MODE_USER}-mode)"
  5437.     # FIXME: late fix for Caldera scd
  5438.     mv $FILE_SYSTEM_CONF $FILE_SYSTEM_CONF.tmp
  5439.     sed -e 's:/dev/sr:/dev/scd:g' < $FILE_SYSTEM_CONF.tmp > $FILE_SYSTEM_CONF
  5440.     rm -f $FILE_SYSTEM_CONF.tmp
  5441.  
  5442.     if [ -f /var/run/cardmgr.pid ]; then
  5443.         rm -f /sbin/cardmgr
  5444.         rm -fr /etc/pcmcia
  5445.         kill -9 `cat /var/run/cardmgr.pid`
  5446.     fi
  5447.  
  5448.     while [ 1 ]; do
  5449.         INSTALL_STATE="`do_calc $INSTALL_STATE - 1`"
  5450.         Debug "entering install stage $INSTALL_STATE ..."
  5451.         if [ $INSTALL_STATE -gt $max_state_seen ]; then
  5452.             max_state_seen=$INSTALL_STATE
  5453.         fi
  5454.         case $INSTALL_STATE in
  5455.         0)
  5456.             # quit LISA
  5457.             end_use INSTALL
  5458.             end_use CALDERA_INSTALL
  5459.             end_use RPM_INSTALL
  5460.             end_use /usr/lib/LST/libLSTall
  5461.             return 1
  5462.             ;;
  5463.         1)
  5464.             # quit LISA
  5465.             Debug "User wanted to exit LISA. Not allowed in First_Install"
  5466.             return 1
  5467.             ;;
  5468.         2)
  5469.             # initial module management
  5470.             InitSubsystems || continue
  5471.             # exit now if we used "boot root=/dev/sdXX" at LILO prompt
  5472.             if [ -f /etc/install.skip ]; then
  5473.                 sync
  5474.                 Do_Clear_Screen
  5475.                 exit 0
  5476.             fi
  5477.             ;;
  5478.         3)
  5479.             # allow repartitioning as soon as possible
  5480.             Debug "Before Menu_Config_Partitioning"
  5481.             Menu_Config_Partitioning || continue
  5482.             Debug "After Menu_Config_Partitioning"
  5483.             ;;
  5484.         4)
  5485.             # enable swapspace as soon as possible
  5486.             # FIXME: omit this question if swapspace was already set up
  5487.             Menu_Config_Swap || continue
  5488.             # FIXME: check if we have less than 12 MB but no swap enabled?
  5489.             ;;
  5490.         5)
  5491.             # choose install source (floppy, hard disk, CDROM, network, ...)
  5492.             Choose_Install_Source || continue
  5493.             # do read files from source
  5494.             Do_Read_Source
  5495.             ;;
  5496.         6)
  5497.             # select target partition(s)
  5498.             prep_use PREPARE
  5499.             Choose_Install_Target || continue
  5500.             end_use PREPARE
  5501.             # do init target partition(s)
  5502.             Do_Init_Target
  5503.             ;;
  5504.         7)
  5505.             # choose packages
  5506.             prep_use SELECT
  5507.             Menu_Pkg_Select || continue
  5508.             ;;
  5509.         8)
  5510.             # install packages
  5511.             prep_use INSTALL
  5512.             Do_Pkg_Install || continue
  5513.             end_use SELECT
  5514.             end_use INSTALL
  5515.             Do_Fixes_After_Pkg_Install
  5516.             Do_Save_Package_Selection
  5517.             INSTALL_STATE="`do_calc $INSTALL_STATE + 1`"
  5518.             ;;
  5519.         9)
  5520.             # FIXME: issue a warning that backsptep means reinstall or reboot
  5521.             Error ":ERR_BACKSTEP_NOT_POSSIBLE:"
  5522.             Ask_Bool ABORT_INSTALL y
  5523.             if [ "$ANSWER" = "0" ]; then
  5524.                 Do_Reboot
  5525.             fi
  5526.             ;;
  5527.         10)
  5528.             # initial system configuration (to be replaced by COAS)
  5529.             Menu_First_Config || continue
  5530.             Do_Fixes_After_First_Config
  5531.             # umount the second mount of /proc
  5532.             umount /root/proc
  5533.             ;;
  5534.         11)
  5535.             History "`date` $LOGNAME: primary installation completed"
  5536.             History "==============================================================="
  5537.             # this file is used as a marker to show that the install is complete
  5538.             touch /etc/install.done
  5539.             umount /mnt >/dev/null 2>&1
  5540.             rmmod smbfs >/dev/null 2>&1
  5541.             if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" != "SBA" ]; then
  5542.                 Msg2 GRATULATIONS || continue
  5543.             fi
  5544.             # FIXME: need better method to find initrd
  5545.             if [ "`uname -r`" != "1.2.13" ]; then
  5546.                 sync
  5547.                 Do_Clear_Screen
  5548.                 exit 0
  5549.             else
  5550.                 Do_Reboot_System
  5551.             fi
  5552.             ;;
  5553.         esac
  5554.         INSTALL_STATE="`do_calc $INSTALL_STATE + 2`"
  5555.     done
  5556. }
  5557.  
  5558. Do_Set_Password()
  5559. {
  5560.     local username=$1
  5561.  
  5562.     prep_use /bin/passwd
  5563.     reset 2>&1
  5564.     Do_Clear_Screen
  5565.     # small passwd wrapper
  5566.     while [ 1 ]; do
  5567.         touch /tmp/.passwd
  5568.         echo "Setting password for $username:"
  5569.               if [ "$MODE_QUERY" = "auto" ]; then
  5570.             sleep 1 # sleep a second to make sure file is older
  5571.             sed "s/^$username:[^:]*:/$username:*notset*:/" /etc/passwd > /etc/passwd.tmp
  5572.             chown root.root /etc/passwd.tmp
  5573.             chmod 644 /etc/passwd.tmp
  5574.             mv /etc/passwd.tmp /etc/passwd
  5575.         else
  5576.             passwd $username 2>&1
  5577.         fi
  5578.         if [ /etc/passwd -nt /tmp/.passwd ]; then
  5579.             break
  5580.         fi
  5581.     done
  5582.     return 0
  5583. }
  5584.  
  5585. Do_Set_Root_Password()
  5586. {
  5587.     Msg2 SET_ROOT_PASSWD || return 1
  5588.     Do_Set_Password root
  5589.     return 0
  5590. }
  5591.  
  5592. Do_Create_First_User()
  5593. {
  5594.     Msg2 CREATE_FIRST_USER || return 1
  5595.     Menu_User_Add --first
  5596. }
  5597.  
  5598. Menu_Config_Network()
  5599. {
  5600.     local s=2
  5601.  
  5602.     while [ 1 ]; do
  5603.         s="`do_calc $s - 1`"
  5604.         Debug "entering net config stage $s ..."
  5605.         case $s in
  5606.         0)
  5607.             return 1
  5608.             ;;
  5609.         1)
  5610.             Menu_Config_FQ_Name || continue
  5611.             Do_Ifcfg lo up
  5612.             ;;
  5613.         2)
  5614.             Menu_Config_Ether || continue
  5615.             if [ "`Get_Val CONF_eth0_STAT`" != "up" -a \
  5616.             "`Get_Val CONF_tr0_STAT`" != "up" ]; then
  5617.                 # disable router, DNS and NIS
  5618.                 # (this is dumb but prevents from trouble)
  5619.                 # jump over the next steps
  5620.                 CONF_ROUTER1_IP=""
  5621.                 CONF_DNS_DOMAIN=""
  5622.                 CONF_DNS_SEARCH=""
  5623.                 CONF_DNS_SERVER1_IP=""
  5624.                 CONF_DNS_SERVER2_IP=""
  5625.                 CONF_DNS_SERVER3_IP=""
  5626.                 CONF_NIS_DOMAIN=""
  5627.                 CONF_NIS_SERVER1_IP=""
  5628.                 CONF_NIS_SERVER2_IP=""
  5629.                 CONF_NIS_SERVER3_IP=""
  5630.                 s=99
  5631.             fi
  5632.             ;;
  5633.         3)
  5634.             Menu_Config_Router first || continue
  5635.             ;;
  5636.         4)
  5637.             Menu_Config_DNS || continue
  5638.             ;;
  5639.         5)
  5640.             if [ -x $DIR_TARGET/usr/sbin/ypbind ]; then
  5641.                 Menu_Config_NIS || continue
  5642.             fi
  5643.             ;;
  5644.         *)
  5645.             return 0
  5646.             ;;
  5647.         esac
  5648.         s="`do_calc $s + 2`"
  5649.     done
  5650. }
  5651.  
  5652. Build_Daemons()
  5653. {
  5654.     local i
  5655.     local daemon
  5656.     local ghostdaemon
  5657.     local variant
  5658.     local descriptive
  5659.     local onboot
  5660.     local ident
  5661.     local desc
  5662.     local preset
  5663.     local have_mta=false
  5664.  
  5665.     for i in $DIR_TARGET/etc/sysconfig/daemons/* ; do
  5666.         if [ ! -f $i ]; then continue ; fi
  5667.         daemon="`basename $i`"
  5668.         if [ "$daemon" = "mta" ]; then
  5669.             have_mta=true
  5670.         fi
  5671.  
  5672.         # filter out wrong (old) sendmail/smail files if mta exists
  5673.         if [ "$daemon" = "sendmail" -a "$have_mta" = "true" ]; then
  5674.             continue
  5675.         fi
  5676.         if [ "$daemon" = "smail" -a "$have_mta" = "true" ]; then
  5677.             continue
  5678.         fi
  5679.  
  5680.         # filter out .rpmsave and .rpmorig files
  5681.         ghostdaemon="`basename $i .rpmsave`"
  5682.         if [ "$daemon" != "$ghostdaemon" ]; then continue ; fi
  5683.         ghostdaemon="`basename $i .rpmorig`"
  5684.         if [ "$daemon" != "$ghostdaemon" ]; then continue ; fi
  5685.  
  5686.         hack="$daemon"
  5687.         onboot="`get_val -f $i ONBOOT`"
  5688.         ident="`get_val -f $i IDENT`"
  5689.         case $ident in
  5690.         DOSEmu)
  5691.             hack="DOS Emulation"
  5692.             ;;
  5693.         lpd)
  5694.             hack="Print Server"
  5695.             ;;
  5696.         news-system)
  5697.             hack="News Server"
  5698.             ;;
  5699.         nis-server)
  5700.             hack="NIS Server"
  5701.             ;;
  5702.         MTA)
  5703.             hack="Mail Server"
  5704.             ;;
  5705.         NFS)
  5706.             hack="NFS Server"
  5707.             ;;
  5708.         SAMBA)
  5709.             hack="SMB Server"
  5710.             ;;
  5711.         WWW)
  5712.             hack="WEB server"
  5713.             ;;
  5714.         esac
  5715.         descriptive="`get_val -f $i DESCRIPTIVE`"
  5716.         if [ -n "$descriptive" ]; then
  5717.             hack="$descriptive"
  5718.         fi
  5719.         variant="`get_val -f $i VARIANT`"
  5720.         desc=
  5721.         if [ -n "$variant" ]; then
  5722.             desc="$variant"
  5723.         fi
  5724.         if [ -n "$desc" ]; then
  5725.             desc=" (${desc})"
  5726.         fi
  5727.         preset=S      
  5728.         case $onboot in
  5729.         no|NO|No)
  5730.             preset=U       
  5731.             ;;
  5732.         esac
  5733.         # FIXME12: syslog does not respect the syntax.
  5734.         # set_val can not handle it.
  5735.         if [ "$daemon" = "syslog" ]; then
  5736.             preset=F
  5737.         fi
  5738.         echo "\"$daemon\" \"${hack}${desc}\" \"$preset\" \\"
  5739.     done
  5740. }
  5741.  
  5742. # Do_Setup_Daemon DAEMON {yes,no}
  5743. #
  5744. Do_Setup_Daemon()
  5745. {
  5746.     local dir_daemons=$DIR_TARGET/etc/sysconfig/daemons
  5747.  
  5748.     # FIXME12: syslog does not respect syntax. set_val can not handle it.
  5749.     if [ "$1" = "syslog" ]; then
  5750.         return 0
  5751.     fi
  5752.     if [ -f ${dir_daemons}/$1 ]; then
  5753.         set_val -f ${dir_daemons}/$1 ONBOOT $2
  5754.     else
  5755.         echo "ONBOOT=$2" > ${dir_daemons}/$1
  5756.     fi
  5757. }
  5758.  
  5759. Do_Setup_Daemons()
  5760. {
  5761.     local i
  5762.     local daemon
  5763.     local daemon_list="$1"
  5764.  
  5765.     # Do the necessary enable/disable modifications
  5766.     for i in $DIR_TARGET/etc/sysconfig/daemons/* ; do
  5767.         if [ ! -f $i ]; then continue ; fi
  5768.         daemon="`basename $i`"
  5769.         if [ -n "`echo "$daemon_list" | fgrep ":${daemon}:"`" ]; then
  5770.             Do_Setup_Daemon $daemon yes
  5771.         else
  5772.             Do_Setup_Daemon $daemon no
  5773.         fi
  5774.     done
  5775.  
  5776.     # Save ':'-separated list of daemons to be autostarted
  5777.     Do_Store CONF_DAEMON_SERVICES "$daemon_list"
  5778. }
  5779.  
  5780. Menu_Config_Daemons()
  5781. {
  5782.     local daemon
  5783.     local daemon_list
  5784.  
  5785.     Choose --multi --build Build_Daemons CONFIG_DAEMONS || return 1
  5786.  
  5787.     # The list of selected daemons for autostart is now in $FILE_TMP_ANSWER
  5788.     # and we store it as a ':'-separated list in the CONF_DAEMON_SERVICES
  5789.     # variable in /etc/system.cnf
  5790.     for daemon in `cat $FILE_TMP_ANSWER` ; do
  5791.         daemon_list="${daemon_list}:${daemon}"
  5792.     done
  5793.     if [ -n "$daemon_list" ]; then
  5794.         daemon_list="${daemon_list}:"
  5795.     fi
  5796.  
  5797.     Do_Setup_Daemons "$daemon_list"
  5798.     return 0
  5799. }
  5800.  
  5801. Get_MBR_dev()
  5802. {
  5803.     sysinfo --tag -C MBR --disk
  5804. }
  5805.  
  5806. Replace_MBR()
  5807. {
  5808.     local src=/boot/virgin.mbr
  5809.     local tgt=$1
  5810.  
  5811.     if [ ! -f $src ]; then
  5812.         Debug "could not find $src to replace $tgt"
  5813.         return 1
  5814.     fi
  5815.     dd if=$src of=$tgt bs=446 count=1 && {
  5816.         dd if=$src skip=510 bs=1 count=2 of=$tgt seek=510 && {
  5817.             Debug "sucessfully replaced $tgt with $src"
  5818.             return 0
  5819.         }
  5820.     }
  5821.     Debug "problems replacing $tgt"
  5822.     return 1
  5823. }
  5824.  
  5825. Do_Fix_MBR()
  5826. {
  5827.     local boot_sig_crc="b016f118"
  5828.     local real_sig_crc=
  5829.     local mbr_dev=
  5830.  
  5831.     mbr_dev="`Get_MBR_dev`"
  5832.     if [ -z "$mbr_dev" ]; then
  5833.         Debug "Get_MBR_dev returned nothing"
  5834.         return 1
  5835.     fi
  5836.     dd if=$mbr_dev bs=1 skip=510 count=2 of=/tmp/sig.mbr
  5837.     gzip -9 /tmp/sig.mbr 
  5838.     real_sig_crc="`gzip -lv /tmp/sig.mbr.gz | fgrep -v method | cut -d' ' -f 2`"
  5839.     Debug "real_sig_crc was <$real_sig_crc>"
  5840.     if [ -z "$real_sig_crc" ]; then
  5841.         Debug "real_sig_crc was empty"
  5842.         return 1
  5843.     fi
  5844.     if [ "$real_sig_crc" = "$boot_sig_crc" ]; then
  5845.         # for now be happy with that (simplified approach)
  5846.         return 0
  5847.     fi
  5848.     Debug "real_sig_crc != boot_sig_crc ==> replacing MBR"
  5849.     Replace_MBR $mbr_dev || return 1
  5850.     return 0
  5851. }
  5852.  
  5853. Menu_First_Config()
  5854. {
  5855.     local s
  5856.  
  5857.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" = "SBA" ]; then
  5858.         s=102
  5859.     else
  5860.         s=2
  5861.     fi
  5862.  
  5863.     Start_unconfigured_sh
  5864.  
  5865.     while [ 1 ]; do
  5866.         s="`do_calc $s - 1`"
  5867.         Debug "entering config stage $s ..."
  5868.         case $s in
  5869.         0|100)
  5870.             return 1
  5871.             ;;
  5872.         1)
  5873.             Menu_Config_Network || continue
  5874.             ;;
  5875.         101)
  5876.               Do_Setup_FQ_Name
  5877.             Do_Ifcfg lo up
  5878.             Do_Setup_Hosts
  5879.             if [ -z "`fgrep eth0 /proc/net/dev`" ]; then
  5880.                 Error "$dev ; :ERR_NO_DEVICE_AND_NO_MODULE:"
  5881.                 Do_Store CONF_eth0_STAT down
  5882.             else
  5883.                 Do_Store CONF_eth0_STAT up
  5884.                 Do_Store CONF_eth0_DEV "eth0"
  5885.                 Do_Store CONF_eth0_NAME "sba.local"
  5886.                 Do_Store CONF_eth0_IP "192.168.1.1"
  5887.                 Do_Store CONF_eth0_MASK "255.255.255.0"
  5888.                 Do_Store CONF_eth0_NET "192.168.1.0"
  5889.                 Do_Store CONF_eth0_BCAST "192.168.1.255"
  5890.                 Do_Store CONF_ROUTER1_IP "192.168.1.1"
  5891.                 Do_Setup_Hosts
  5892.                 Set_network
  5893.                 Set_ifcfg eth0
  5894.                 Do_Ifcfg eth0 up > $FILE_TMP_ERR 2>&1
  5895.                   Do_Ifcfg default up
  5896.             fi
  5897.               Do_Store CONF_DNS_SERVER1_IP "192.168.1.1"
  5898.             Do_Setup_DNS
  5899.             ;;
  5900.         2|102)
  5901.             Menu_Config_Timezone || continue
  5902.             ;;
  5903.         3)
  5904.             Menu_Config_Mouse || continue
  5905.             ;;
  5906.         4|103)
  5907.             Menu_Config_Printer || continue
  5908.             ;;
  5909.         5|104)
  5910.             Do_Set_Root_Password || continue
  5911.             ;;
  5912.         6|105)
  5913.             Do_Create_First_User || continue
  5914.             Fix_passwd
  5915.             ;;
  5916.         7)
  5917.             # omit this question if install source was CD
  5918.             if [ "`Get_Val CONF_INSTALL_MEDIUM`" != "cdrom" ]; then
  5919.                 Menu_Config_CD || continue
  5920.             fi
  5921.             ;;
  5922.         8|106)
  5923.             prep_use LILO
  5924.             while [ 1 ]; do
  5925.                 Menu_Config_LILO_HD && break
  5926.                 Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  5927.             done
  5928.             Do_Fix_MBR
  5929.             ;;
  5930.         9)
  5931.             # configure daemons during first install
  5932.             Menu_Config_Daemons || continue
  5933.             ;;
  5934.         10)
  5935.             # configure X during first install
  5936.             if [ -f $DIR_TARGET/usr/X11R6/bin/startx ]; then
  5937.                 while [ 1 ]; do
  5938.                     Menu_Config_X_Server && break
  5939.                     Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  5940.                 done
  5941.             fi
  5942.             ;;
  5943.         11)
  5944.             # store LISA configuration on floppy
  5945.             while [ 1 ]; do
  5946.                 Menu_Store_LISA_Config && break
  5947.                 Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  5948.             done
  5949.             ;;
  5950.         12|107)
  5951.             # first configuration finished
  5952.             return 0
  5953.             ;;
  5954.         *)
  5955.             Panic "Menu_First_Config: should never get here."
  5956.             return 1
  5957.             ;;
  5958.         esac
  5959.         s="`do_calc $s + 2`"
  5960.     done
  5961. }
  5962.  
  5963. Do_Save_Package_Selection()
  5964. {
  5965.     if [ -f $FILE_PKGS_SEL ]; then
  5966.         cp -a $FILE_PKGS_SEL $DIR_TARGET/usr/lib/LST/pkgs.sel
  5967.     fi
  5968. }
  5969.  
  5970. Do_Store_LISA_Config()
  5971. {
  5972.   local was_mounted=
  5973.   local happy
  5974.   local i
  5975.  
  5976.   while [ 1 ]; do
  5977.       happy=true
  5978.       mount | fgrep 'on /floppy' > /dev/null && was_mounted=true
  5979.       umount /floppy >/dev/null 2>&1
  5980.     if [ $? -ne 0 ]; then
  5981.         echo "could not unmount" >> /dev/tty8
  5982.     fi
  5983.       Msg ":DO_INSERT_DOS_FLOPPY:" || return 1
  5984.       mount -t msdos /dev/fd0H1440 /floppy
  5985.       if [ $? -ne 0 ]; then
  5986.           Msg ":ERR_MOUNT_FLOPPY_FAILED:"
  5987.         return 1
  5988.       else
  5989.         touch /floppy/writable
  5990.         if [ $? -ne 0 ]; then
  5991.             # floppy write protected
  5992.             # FIXME
  5993.               # Msg ":ERR_MOUNT_FLOPPY_FAILED:"
  5994.               Msg "Write failed. The floppy is write protected."
  5995.             continue
  5996.         else
  5997.             rm -f /floppy/writable
  5998.         fi
  5999.     fi
  6000.     Info ":INFO_WAIT:"
  6001.     mkdir -p /floppy/etc
  6002.     mkdir -p /floppy/usr/lib/LST
  6003.     for i in /etc/lst.cnf /etc/system.cnf /usr/lib/LST/pkgs.sel ; do
  6004.         if [ -f $i ]; then
  6005.             cp -a $i /floppy/$i
  6006.             if [ $? -ne 0 ]; then
  6007.                 Debug "problems while copying $i"
  6008.                 happy=false
  6009.             fi
  6010.         else
  6011.             Debug "$i can not be copied: file not found"
  6012.             happy=false
  6013.         fi
  6014.     done
  6015.     sync
  6016.     sync
  6017.     umount /floppy >/dev/null 2>&1
  6018.     if [ "$happy" = "true" ]; then
  6019.         # FIXME
  6020.         # Msg ":INFO_WRITE_SUCCEEDED:" || continue
  6021.         Msg "The configuration has been saved successfully." || continue
  6022.         return 0
  6023.     fi
  6024.     Msg ":ERR_WRITE_FAILED:" || return 1
  6025.   done
  6026.   return 0
  6027. }
  6028.  
  6029. Menu_Store_LISA_Config()
  6030. {
  6031.     local defval
  6032.  
  6033.     if [ "$MODE_QUERY" = "auto" ]; then
  6034.         defval=n
  6035.     else
  6036.         defval=y
  6037.     fi
  6038.  
  6039.     while [ 1 ]; do
  6040.         Ask_Bool WRITE_CURRENT_CONFIG $defval || return 1
  6041.         case $ANSWER in
  6042.         0)
  6043.             Do_Store_LISA_Config || continue
  6044.             ;;
  6045.         esac
  6046.         return 0
  6047.     done
  6048. }
  6049.  
  6050. Set_LISA_CONF()
  6051. {
  6052.   mkdir -p $DIR_TARGET/etc
  6053.  
  6054.   # save lst setup
  6055.   cp -a /etc/lst.cnf $DIR_TARGET/etc
  6056.  
  6057.   # save system setup
  6058.   cp -a /etc/system.cnf $DIR_TARGET/etc
  6059.  
  6060.   # reset target and auto mode
  6061.   set_val -f $DIR_TARGET/etc/system.cnf DIR_TARGET "/"
  6062.   set_val -f $DIR_TARGET/etc/system.cnf MODE_QUERY "prompt"
  6063. }
  6064.  
  6065. Transfer_dev_symlinks()
  6066. {
  6067.   local i
  6068.  
  6069.   # save mouse/modem/cdrom symlinks
  6070.   for i in mouse modem cdrom ; do
  6071.     if [ -L /dev/$i ]; then
  6072.       rm -f $DIR_TARGET/dev/$i
  6073.       cp -a /dev/$i $DIR_TARGET/dev
  6074.     fi
  6075.   done
  6076. }
  6077.  
  6078. Set_message()
  6079. {
  6080.     conf_file=/boot/message
  6081.  
  6082.     # copy boot message
  6083.     if [ ! -f $DIR_TARGET$conf_file ]; then
  6084.         cp -a $conf_file $DIR_TARGET$conf_file
  6085.     fi
  6086. }
  6087.  
  6088. # make sure /opt/bin exists and /opt has enough disk space
  6089. Fix_opt()
  6090. {
  6091.   local root_dev
  6092.   local opt_dev
  6093.   local usr_dev
  6094.  
  6095.   mkdir -p $DIR_TARGET/opt/bin
  6096.  
  6097.   # determine target "/" device
  6098.   root_dev="`df /root | fgrep '%' | cut -c 1-10`"
  6099.  
  6100.   # determine target "/opt" device
  6101.   opt_dev="`df /root/opt | fgrep '%' | cut -c 1-10`"
  6102.  
  6103.   # determine target "/usr" device
  6104.   usr_dev="`df /root/usr | fgrep '%' | cut -c 1-10`"
  6105.  
  6106.   # if /opt is a separate partition nothing has to be done
  6107.   if [ -n "$opt_dev" ]; then
  6108.     if [ "$opt_dev" != "$root_dev" ]; then return 0 ; fi
  6109.   fi
  6110.  
  6111.   # if /usr is a separate partition we create a symlink /opt -> /usr/opt
  6112.   if [ "$usr_dev" != "$root_dev" ]; then
  6113.     mkdir -p $DIR_TARGET/usr/opt
  6114.     if [ -n "`ls $DIR_TARGET/opt`" ]; then
  6115.         cp -aR $DIR_TARGET/opt/* $DIR_TARGET/usr/opt
  6116.     fi
  6117.     rm -fr $DIR_TARGET/opt
  6118.     ln -s usr/opt $DIR_TARGET/opt
  6119.   # otherwise we create a directory
  6120.   else
  6121.     mkdir -p $DIR_TARGET/opt
  6122.   fi
  6123. }
  6124.  
  6125. # FIXME: we have to rely that the linux symlink is there, otherwise 
  6126. #        we are running into a chicken and egg problem to determine
  6127. #        the future value of 'uname -r' and 'uname -v'. Now use
  6128. #     the value of the running kernel as fallback
  6129. Get_uname_r()
  6130. {
  6131.     local uname_r
  6132.  
  6133.     if [ -f $DIR_TARGET/usr/src/linux/include/linux/version.h ]; then
  6134.         fgrep UTS_RELEASE $DIR_TARGET/usr/src/linux/include/linux/version.h | cut -d'"' -f 2 > $FILE_TMP_VAL
  6135.         uname_r="`cat $FILE_TMP_VAL`"
  6136.     else
  6137.         uname_r="`uname -r`"
  6138.     fi
  6139.     Debug "Get_uname_r returns $uname_r"
  6140.     echo "$uname_r"
  6141. }
  6142.  
  6143. Get_uname_v()
  6144. {
  6145.     local uname_v
  6146.  
  6147.     if [ -f $DIR_TARGET/usr/src/linux/include/linux/compile.h ]; then
  6148.         fgrep UTS_VERSION $DIR_TARGET/usr/src/linux/include/linux/compile.h | cut -d'"' -f 2 > $FILE_TMP_VAL
  6149.         uname_v="`cat $FILE_TMP_VAL`"
  6150.     else
  6151.         uname_v="`uname -v`"
  6152.     fi
  6153.     Debug "Get_uname_v returns $uname_v"
  6154.     echo "$uname_v"
  6155. }
  6156.  
  6157. #
  6158. # prepare a valid initrd (all relative to PWD)
  6159. #
  6160. Prepare_Initrd()
  6161. {
  6162.   # FIXME12uname: because of the rebuild uname -v causes problems
  6163.   local uname_r="`Get_uname_r`"
  6164.   local uname_v="`Get_uname_v`"
  6165.   local mod_file="/etc/modules/${uname_r}/${uname_v}.rootfs"
  6166.   local driver
  6167.   local moddir
  6168.   local module
  6169.   local ans
  6170.  
  6171.   # create minimal directories
  6172.   mkdir -p bin dev etc/rc.d etc/modules/${uname_r} etc/modules/options lib/modules/${uname_r} sbin
  6173.  
  6174.   # create minimal devices
  6175.   mknod -m 644 dev/tty0 c 4 0
  6176.   mknod -m 644 dev/tty1 c 4 1
  6177.   ln -s tty0 dev/console
  6178.  
  6179.   # copy minimal libraries
  6180.   cp -a /lib/libc* lib
  6181.   cp -a /lib/ld.so* lib
  6182.   cp -a /etc/ld.so.conf etc
  6183.  
  6184.   # copy minimal binaries
  6185.   cp -a /bin/sh bin
  6186.   cp -a /sbin/insmod sbin
  6187.   cp -a /bin/uname bin
  6188.   cp -a /bin/cat bin
  6189.  
  6190.   for moddir in block cdrom fs ipv4 misc net pcmcia scsi sound ; do
  6191.     mkdir -p ./lib/modules/${uname_r}/$moddir
  6192.   done
  6193.  
  6194.   # copy rootfs module list and corresponding modules and params files
  6195.   if [ -f "$DIR_TARGET/$mod_file" ]; then
  6196.     cp -a "$DIR_TARGET/$mod_file" ./"$mod_file"
  6197.     # copy necessary modules
  6198.     for driver in `cat "$DIR_TARGET/$mod_file"` ; do
  6199.       for moddir in block cdrom fs ipv4 misc net pcmcia scsi sound ; do
  6200.         module=/lib/modules/${uname_r}/$moddir/${driver}.o
  6201.     # we use the modules from the target system
  6202.     if [ -f $DIR_TARGET/$module ]; then
  6203.       mkdir -p /lib/modules/${uname_r}/$moddir
  6204.       cp -a $DIR_TARGET/$module ./$module
  6205.       Debug "$module copied to initrd from target system"
  6206.     else
  6207.       Debug "did not find module $DIR_TARGET/$module to be copied to initrd"
  6208.     fi
  6209.       done
  6210.       if [ -s /etc/modules/options/$driver ]; then
  6211.         cp -a /etc/modules/options/$driver etc/modules/options
  6212.     Debug "/etc/modules/options/$driver copied to initrd"
  6213.       fi
  6214.     done
  6215.   else
  6216.     Debug "<$mod_file> not found"
  6217.   fi
  6218.  
  6219.   # copy module autoload routine
  6220.   cp -a /etc/rc.d/rc.rootfs etc/rc.d
  6221.  
  6222.   # this is used to trigger a initrd umount and freeramdisk in rc.boot
  6223.   touch free_initrd
  6224.  
  6225.   # create a very simple linuxrc
  6226.   echo '#!/bin/sh' > linuxrc
  6227.   echo "/bin/sh /etc/rc.d/rc.rootfs" >> linuxrc
  6228.   echo "exit 0" >> linuxrc
  6229.   chmod 755 linuxrc
  6230. }
  6231.  
  6232. #
  6233. # create compressed initrd image using the loop mount
  6234. #
  6235. Create_Initrd()
  6236. {
  6237.   local LoopFile=$DIR_TARGET/tmp/loopfile
  6238.   local LoopFileSize=2880
  6239.   local LoopMountPoint=$DIR_TARGET/mnt
  6240.   local InitrdImage=$DIR_TARGET/boot/initrd.gz
  6241.  
  6242.   Do_Clear_Screen
  6243.   echo "Preparing initrd..."
  6244.   echo
  6245.  
  6246.   prep_use LOOP
  6247.   prep_use PREPARE
  6248.  
  6249.   # load loop support
  6250.   Do_Load_Module --silent loop block
  6251.  
  6252.   # clear loopfile
  6253.   dd if=/dev/zero of=$LoopFile bs=1k count=$LoopFileSize
  6254.  
  6255.   # create loop device if necessary
  6256.   if [ ! -b /dev/loop0 ]; then
  6257.     mknod -m 666 /dev/loop0 b 7 0
  6258.   fi
  6259.  
  6260.   # prepare loop file for mount
  6261.   losetup /dev/loop0 $LoopFile
  6262.  
  6263.   # create filesystem on loopfile
  6264.   mke2fs /dev/loop0 $LoopFileSize
  6265.  
  6266.   echo
  6267.   echo "Please wait..."
  6268.  
  6269.   # mount loopfile as block device (needs mount >= 2.5k)
  6270.   mount -t ext2 /dev/loop0 $LoopMountPoint
  6271.  
  6272.   # create a minimal initrd for this system
  6273.   ( cd $LoopMountPoint ; Prepare_Initrd )
  6274.  
  6275.   # unmount it
  6276.   umount /dev/loop0
  6277.  
  6278.   # create compressed initrd from it
  6279.   dd if=/dev/loop0 bs=1k count=$LoopFileSize | gzip -9 > $InitrdImage
  6280.  
  6281.   # detach it
  6282.   losetup -d /dev/loop0
  6283.  
  6284.   # remove loopfile
  6285.   rm -f $LoopFile
  6286.  
  6287.   # unload loop support
  6288.   rmmod loop
  6289.  
  6290.   # FIXME: add it as default LILO entry
  6291.   # currently we trigger if a $DIR_TARGET/boot/initrd.gz is present
  6292.  
  6293.   end_use LOOP
  6294.   end_use PREPARE
  6295.  
  6296.   sleep 3
  6297. }
  6298.  
  6299. Is_SCSI_Root()
  6300. {
  6301.   local root_dev="`Get_Val CONF_INSTALL_ROOT`"
  6302.  
  6303.   echo "$root_dev" | fgrep "/dev/sd" > /dev/null && return 0
  6304.   return 1
  6305. }
  6306.  
  6307. # check if we use an ethercard
  6308. Is_Etherhost()
  6309. {
  6310.   cat /proc/net/dev | fgrep eth0 > /dev/null && return 0
  6311.   return 1
  6312. }
  6313.  
  6314. Set_initrd()
  6315. {
  6316.   local need_initrd=
  6317.  
  6318.   Is_SCSI_Root && need_initrd=true
  6319.   # Is_Etherhost && need_initrd=true
  6320.   if [ -n "$need_initrd" ]; then
  6321.     # we need a initrd
  6322.     Create_Initrd
  6323.   else
  6324.     # we don't need a initrd
  6325.     rm -fr $DIR_TARGET/initrd/*
  6326.   fi
  6327.   return 0
  6328. }
  6329.  
  6330. Set_modules_autoload()
  6331. {
  6332.   local uname_r="`Get_uname_r`"
  6333.   local uname_v="`Get_uname_v`"
  6334.   local confpath="/etc/modules/${uname_r}"
  6335.   local driver
  6336.   local mod_file
  6337.   local param_file
  6338.  
  6339.   # modules loaded by LISA were stored in this file
  6340.   local lisa_modules_file=/tmp/modules.initrd
  6341.   touch $lisa_modules_file
  6342.  
  6343.   # modules already handled will be stored in this file
  6344.   local handled_modules_file=$DIR_TARGET/tmp/modules.handled
  6345.   mkdir -p $DIR_TARGET/tmp
  6346.   rm -f $handled_modules_file
  6347.   touch $handled_modules_file
  6348.  
  6349.   # modules needed for the rootfs will be stored in this file
  6350.   # FIXME12uname: because of the rebuild uname -v causes problems
  6351.   local rootfs_modules_file="$DIR_TARGET$confpath/${uname_v}.rootfs"
  6352.   rm -f "$rootfs_modules_file"
  6353.   touch "$rootfs_modules_file"
  6354.  
  6355.   # modules needed for everything but the rootfs will be stored in this file
  6356.   # FIXME12uname: because of the rebuild uname -v causes problems
  6357.   local non_rootfs_modules_file="$DIR_TARGET$confpath/${uname_v}.default"
  6358.   mkdir -p $DIR_TARGET/etc/modules/options
  6359.   mkdir -p $DIR_TARGET$confpath
  6360.   rm -f "$non_rootfs_modules_file"
  6361.   touch "$non_rootfs_modules_file"
  6362.  
  6363.   # The list of modules to be autoloaded consists of 3 parts:
  6364.   # 1. modules loaded by LISA (during autoprobing and on user's request)
  6365.   local lisa_modules="`cat $lisa_modules_file`"
  6366.   # 2. modules that are loaded now (that we don't miss manually loaded modules)
  6367.   local loaded_modules="`cat /proc/modules | cut -d' ' -f 1`"
  6368.   # 3. modules that we want always to be loaded 
  6369.   local default_modules="sunrpc lockd fat msdos umsdos vfat parport parport_pc parport_probe soundcore soundlow 8390 scsi_mod sd_mod sr_mod st sg nfs isofs lp slhc slip ppp ipx"
  6370.  
  6371.   # The modules may be autoloaded in 2 steps:
  6372.   # 1. modules required to load the root filesystem thus loaded in the initrd
  6373.   #    (this is only necessary if ethercard used or rootfs on a SCSI device)
  6374.   local need_initrd=
  6375.   # 2. other modules 
  6376.  
  6377.   # check if rootfs on SCSI
  6378.   Is_SCSI_Root && need_initrd=true
  6379.  
  6380.   # check if we use an ethercard
  6381.   # FIXME: we don't support NFS mounted root at the moment
  6382.   # Is_Etherhost && need_initrd=true
  6383.  
  6384.   # store modules and their params in the appropriate autoload files
  6385.   for driver in $lisa_modules $loaded_modules $default_modules ; do
  6386.     if [ -n "`fgrep -x $driver "$handled_modules_file"`" ]; then
  6387.       Debug "'$driver' is already handled"
  6388.       continue
  6389.     fi
  6390.     echo "$driver" >> "$handled_modules_file"
  6391.     Debug "added '$driver' to '$handled_modules_file'"
  6392.     mod_file="$non_rootfs_modules_file"
  6393.     param_file="$DIR_TARGET/etc/modules/options/$driver"
  6394.     if [ -n "$need_initrd" ]; then
  6395.       # FIXME: this is a dumb check for scsi driver (should be done by sysinfo)
  6396.       if [ -f /lib/modules/`uname -r`/scsi/$driver.o ]; then
  6397.         mod_file="$rootfs_modules_file"
  6398.       fi
  6399.       # FIXME: this is a dumb check for ether driver (should be done by sysinfo)
  6400.       # FIXME: we don't support NFS mounted root at the moment
  6401.       #if [ -f /lib/modules/${uname_r}/net/$driver.o ]; then
  6402.       #  mod_file="$rootfs_modules_file"
  6403.       #fi
  6404.     fi
  6405.     echo "$driver" >> "$mod_file"
  6406.     Debug "added '$driver' to '$mod_file'"
  6407.     if [ -s /etc/modules/options/$driver ]; then
  6408.       Debug "added '`cat /etc/modules/$driver`' to '$param_file'"
  6409.       cp -a /etc/modules/options/$driver $param_file
  6410.     fi
  6411.   done
  6412. }
  6413.  
  6414. Set_etc_HOSTNAME()
  6415. {
  6416.     local conf_file=$DIR_TARGET/etc/HOSTNAME
  6417.     mkdir -p $DIR_TARGET/etc
  6418.     echo "`Get_Val CONF_FQ_HOSTNAME`" > $conf_file
  6419. }
  6420.  
  6421. Set_keyboard()
  6422. {
  6423.     local conf_file=$DIR_TARGET/etc/sysconfig/keyboard
  6424.  
  6425.     echo "KEYTABLE=/usr/lib/kbd/keytables/`Get_Val CONF_KEYBOARD_MAP`" > $conf_file
  6426. }
  6427.  
  6428. Set_clock()
  6429. {
  6430.     local conf_file=$DIR_TARGET/etc/sysconfig/clock
  6431.     local timezone="`Get_Val CONF_TIMEZONE`"
  6432.     local zoneinfo_dir=/usr/share/zoneinfo
  6433.  
  6434.     mkdir -p $DIR_TARGET/etc/sysconfig
  6435.     if [ "`Get_Val CONF_KERNTZ_FLAG`" = "u" ]; then
  6436.         echo "CLOCKMODE=GMT" > $conf_file
  6437.     else
  6438.         echo "CLOCKMODE=LOCAL" > $conf_file
  6439.     fi
  6440.  
  6441.     if [ -z "$timezone" ]; then
  6442.         timezone=GMT
  6443.     fi
  6444.     if [ ! -d $DIR_TARGET$zoneinfo_dir ]; then
  6445.         zoneinfo_dir=/usr/lib/zoneinfo
  6446.     fi
  6447.     # fix symlink only if it's NOT pointing relative to /etc/localtime
  6448.     if [ -z "`ls -l ${DIR_TARGET}${zoneinfo_dir}/localtime | fgrep ' ../../../etc/localtime'`" ]; then
  6449.         ln -sf ../../../etc/localtime ${DIR_TARGET}${zoneinfo_dir}/localtime
  6450.     fi
  6451.     rm -f $DIR_TARGET/etc/localtime
  6452.     mkdir -p $DIR_TARGET/etc
  6453.     ln -sf ..${zoneinfo_dir}/$timezone $DIR_TARGET/etc/localtime
  6454. }
  6455.  
  6456. Set_pcmcia()
  6457. {
  6458.   local conf_file=$DIR_TARGET/etc/sysconfig/pcmcia
  6459.  
  6460.   # check if we used pcmcia during install
  6461.   # (in this case some modules were loaded from rc.S)
  6462.   if [ -n "`fgrep pcmcia_core /proc/modules`" ]; then
  6463.     echo "PCMCIA=yes" > $conf_file
  6464.     if [ -n "`fgrep i82365 /proc/modules`" ]; then
  6465.       echo "PCIC=i82365" >> $conf_file
  6466.     elif [ -n "`fgrep tcic /proc/modules`" ]; then
  6467.       echo "PCIC=tcic" >> $conf_file
  6468.     else
  6469.       # ??? shouldn't happpen
  6470.       echo "PCIC=" >> $conf_file
  6471.     fi
  6472.   else
  6473.     echo "PCMCIA=no" > $conf_file
  6474.     echo "PCIC=" >> $conf_file
  6475.   fi
  6476.   echo "OPTS=\"poll_interval=300\"" >> $conf_file
  6477. }
  6478.  
  6479. Set_network()
  6480. {
  6481.   local conf_file=$DIR_TARGET/etc/sysconfig/network
  6482.  
  6483.   mkdir -p $DIR_TARGET/etc/sysconfig
  6484.   echo "NETWORKING=yes" > $conf_file
  6485.   echo "HOSTNAME=`Get_Val CONF_FQ_HOSTNAME`" >> $conf_file
  6486.   echo "IF_LIST='lo eth tr sl ppp'" >> $conf_file
  6487. }
  6488.  
  6489. Set_ifcfg()
  6490. {
  6491.     local dev=$1
  6492.     local val=
  6493.     local conf_file=$DIR_TARGET/etc/sysconfig/network-scripts/ifcfg-${dev}
  6494.  
  6495.     mkdir -p $DIR_TARGET/etc/sysconfig/network-scripts
  6496.     echo '#!/bin/sh' > $conf_file
  6497.     case $dev in
  6498.     eth0|eth1)
  6499.         echo '#>>>Device type: ethernet' >> $conf_file
  6500.         ;;
  6501.     tr0)
  6502.         echo '#>>>Device type: token ring' >> $conf_file
  6503.         ;;
  6504.     plip0|plip1|plip2)
  6505.         echo '#>>>Device type: parallel line IP' >> $conf_file
  6506.         ;;
  6507.     esac
  6508.     echo '#>>>Variable declarations:' >> $conf_file
  6509.     echo "DEVICE=`Get_Val CONF_${dev}_DEV`" >> $conf_file
  6510.     echo "IPADDR=`Get_Val CONF_${dev}_IP`" >> $conf_file
  6511.     if [ -n "`Get_Val CONF_${dev}_REMOTE_IP`" ]; then
  6512.         echo "PTPADDR=`Get_Val CONF_${dev}_REMOTE_IP`" >> $conf_file
  6513.         if [ "`echo $dev | cut -c1-4`" = "plip" ]; then
  6514.             cat << EOF >> $conf_file
  6515. # for communication with DOS boxes turn activate
  6516. #IFOPTIONS="arp"
  6517. EOF
  6518.         fi
  6519.     fi
  6520.     echo "NETMASK=`Get_Val CONF_${dev}_MASK`" >> $conf_file
  6521.     echo "NETWORK=`Get_Val CONF_${dev}_NET`" >> $conf_file
  6522.     echo "BROADCAST=`Get_Val CONF_${dev}_BCAST`" >> $conf_file
  6523.     if [ "$dev" = "eth0" -o "`echo $dev | cut -c1-4`" = "plip" ]; then
  6524.         if [ -z "`Get_Val CONF_ROUTER1_IP`" ]; then
  6525.             echo "GATEWAY=none" >> $conf_file
  6526.         else
  6527.             echo "GATEWAY=`Get_Val CONF_ROUTER1_IP`" >> $conf_file
  6528.         fi
  6529.     else
  6530.         echo "GATEWAY=none" >> $conf_file
  6531.     fi
  6532.     if [ "`Get_Val CONF_${dev}_STAT`" = "up" ]; then
  6533.         echo "ONBOOT=yes" >> $conf_file
  6534.     else
  6535.         echo "ONBOOT=no" >> $conf_file
  6536.     fi
  6537.     echo '#>>>End variable declarations' >> $conf_file
  6538.     chmod 755 $conf_file
  6539. }
  6540.  
  6541. Fix_basename()
  6542. {
  6543.   # FIXME: (ugly) overwrite the a.out binary with the ELF version
  6544.   if [ -f $DIR_TARGET/usr/bin/basename ]; then
  6545.     cp -af $DIR_TARGET/usr/bin/basename $DIR_TARGET/bin/basename
  6546.   else
  6547.     if [ ! -f $DIR_TARGET/bin/basename ]; then
  6548.       if [ -f /bin/basename ]; then
  6549.         cp -af /bin/basename $DIR_TARGET/bin/basename
  6550.       fi
  6551.     fi
  6552.   fi
  6553. }
  6554.  
  6555. Fix_Obsolete_Progs()
  6556. {
  6557.   local i
  6558.  
  6559.   Fix_basename
  6560.  
  6561.   # remove obsolete progies from /root
  6562.   for i in floppy README bin/rpmq ; do
  6563.     rm -fr $DIR_TARGET/$i
  6564.   done
  6565.   # remove obsolete libs from /root
  6566.   rm -f $DIR_TARGET/lib/libc.so.4
  6567.   rm -f $DIR_TARGET/lib/libc.so.4.5.24
  6568. }
  6569.  
  6570. Fix_conf_getty()
  6571. {
  6572.   local conf_file=/etc/conf.getty
  6573.   
  6574.   # disable getty's clear-screen behaviour
  6575.   if [ ! -f $DIR_TARGET$conf_file ]; then
  6576.     echo "CLEAR=NO" > $DIR_TARGET$conf_file
  6577.     chmod 644 $DIR_TARGET$conf_file
  6578.   fi
  6579. }
  6580.  
  6581. Fix_rc_sysinit()
  6582. {
  6583.   local conf_file=/etc/rc.d/rc.sysinit
  6584.  
  6585.   # autoload the default modules
  6586.   if [ -z "`fgrep rc.modules $DIR_TARGET$conf_file`" ]; then
  6587.     cat << 'EOF' >> $DIR_TARGET$conf_file
  6588.  
  6589. # Autoload the default modules
  6590. if [ -f /etc/rc.d/rc.modules ]; then
  6591.     /etc/rc.d/rc.modules
  6592. fi
  6593.  
  6594. EOF
  6595.   fi
  6596. }
  6597.  
  6598.  
  6599. # try to detect broken insmod by gzip's CRC and replace it.
  6600. #
  6601. Fix_Broken_Insmod()
  6602. {
  6603.   local badcsum
  6604.  
  6605.   if [ -f $DIR_TARGET/sbin/insmod ]; then
  6606.     cp -a $DIR_TARGET/sbin/insmod $DIR_TARGET/tmp/insmod
  6607.     gzip -9f $DIR_TARGET/tmp/insmod
  6608.     badcsum="`gzip -lv $DIR_TARGET/tmp/insmod.gz | fgrep insmod | cut -c 7-14`"
  6609.     if [ "$badcsum" = "51763471" -o "$badcsum" = "2eca023d" ]; then
  6610.       Debug "broken insmod detected and replaced"
  6611.       cp -a /sbin/insmod $DIR_TARGET/sbin/insmod
  6612.     else
  6613.       Debug "CRC of insmod doesn't match broken one"
  6614.     fi
  6615.     rm -f $DIR_TARGET/tmp/insmod.gz
  6616.   else
  6617.     Debug "no insmod found"
  6618.   fi
  6619. }
  6620.  
  6621. # fix /etc/fstab
  6622. #
  6623. Fix_etc_fstab()
  6624. {
  6625.   local conf_file=$DIR_TARGET/etc/fstab
  6626.   local cd_dev="`Get_Val CONF_CD1_DEV`"
  6627.  
  6628.   # add floppy and cdrom entries in fstab
  6629.   mkdir -p $DIR_TARGET/mnt/floppy
  6630.   mkdir -p $DIR_TARGET/mnt/cdrom
  6631.   cat << 'EOF' >> $conf_file
  6632. #
  6633. /dev/fd0 /mnt/floppy msdos defaults,user,noauto 0 0
  6634. #
  6635. EOF
  6636.   if [ -n "$cd_dev" ]; then
  6637.     echo "$cd_dev /mnt/cdrom iso9660 ro,user,noauto 0 0" >> $conf_file
  6638.   fi
  6639. }
  6640.  
  6641. Fix_ldconfig()
  6642. {
  6643.   export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
  6644.  
  6645.   if [ ! -f /sbin/ldconfig ]; then
  6646.     ln -s $DIR_TARGET/sbin/ldconfig /sbin/ldconfig
  6647.     Debug "creating symlink for /sbin/ldconfig"
  6648.   fi
  6649.   #Debug "running 'chroot $DIR_TARGET ldconfig -X'"
  6650.   #chroot $DIR_TARGET ldconfig -X
  6651.   Debug "running 'chroot $DIR_TARGET sbin/ldconfig'"
  6652.   ( cd $DIR_TARGET; chroot $DIR_TARGET sbin/ldconfig ) > $DIR_TARGET/tmp/ldconfig.out 2>&1
  6653. }
  6654.  
  6655. Fix_lilo()
  6656. {
  6657.     local i
  6658.  
  6659.     prep_use LILO
  6660.  
  6661.     for i in /sbin/lilo /sbin/activate /boot/boot.b /boot/message /boot/any_b.b /boot/any_d.b /boot/os2_d.b /boot/chain.b /etc/lilo.conf.in ; do
  6662.         if [ -f $i.gz ]; then
  6663.             gzip -df $i
  6664.         fi
  6665.         if [ "$CND10_MODE" = "true" ]; then
  6666.             if [ -f $i ]; then
  6667.                 cp -a $i $DIR_TARGET$i
  6668.             fi
  6669.         fi
  6670.     done
  6671. }
  6672.  
  6673. Fix_procps()
  6674. {
  6675.   local i
  6676.  
  6677.   for i in /bin/ps /bin/kill ; do
  6678.     if [ -f $i ]; then
  6679.       cp -a $i $DIR_TARGET$i
  6680.     fi
  6681.   done
  6682. }
  6683.  
  6684. Set_Resolver()
  6685. {
  6686.   local i
  6687.  
  6688.   for i in $FILE_ETC_HOSTS $FILE_ETC_RESOLV_CONF ; do
  6689.     if [ -f $i ]; then
  6690.       cp -a $i $DIR_TARGET$i
  6691.     fi
  6692.   done
  6693. }
  6694.  
  6695. Fix_freeramdisk()
  6696. {
  6697.   if [ "$CND10_MODE" = "true" ]; then
  6698.     # make sure the initrd will be saved and freeramdisk called
  6699.     if [ -f /etc/rc.d/rc.free ]; then
  6700.       cp -a /etc/rc.d/rc.free $DIR_TARGET/etc/rc.d/rc.free
  6701.       cat << EOF >> $DIR_TARGET/etc/rc.d/rc.local
  6702. if [ -x /etc/rc.d/rc.free ]; then
  6703. /etc/rc.d/rc.free
  6704. fi
  6705. EOF
  6706.     fi
  6707.     if [ ! -f /root/bin/freeramdisk ]; then
  6708.       if [ -f /bin/freeramdisk.gz ]; then
  6709.     cp -a /bin/freeramdisk.gz /root/bin
  6710.     gzip -df /root/bin/freeramdisk.gz
  6711.       fi
  6712.     fi
  6713.   fi
  6714. }
  6715.  
  6716. Fix_Missing_Root()
  6717. {
  6718.   mkdir -p $DIR_TARGET/root
  6719. }
  6720.  
  6721. # FIXME: obsolete now?
  6722. Fix_faked_lib_versions()
  6723. {
  6724.   if [ ! -f $DIR_TARGET/usr/lib/libdb.so.2 ]; then
  6725.     ln -s libdb.so.1 $DIR_TARGET/usr/lib/libdb.so.2
  6726.     Debug "Fixing libdb symlink"
  6727.   fi
  6728. }
  6729.  
  6730. Fix_news()
  6731. {
  6732.   echo "IDENT=news-system" > $DIR_TARGET/etc/sysconfig/daemons/news
  6733.   echo "ONBOOT=no" >> $DIR_TARGET/etc/sysconfig/daemons/news
  6734.   chmod 644 $DIR_TARGET/etc/sysconfig/daemons/news
  6735. }
  6736.  
  6737. # FIXME: is now in skeleton.cgz but still necessary for LST 2.2 install
  6738. Fix_daemons()
  6739. {
  6740.   mkdir -p $DIR_TARGET/etc/sysconfig/daemons
  6741. }
  6742.  
  6743.  
  6744. Fix_3c59x()
  6745. {
  6746.   if [ -f /lib/modules/2.0.21/net/3c59x.o.gz ]; then
  6747.     gzip -df /lib/modules/2.0.21/net/3c59x.o.gz
  6748.   fi
  6749.   if [ -f /lib/modules/2.0.21/net/3c59x.o ]; then
  6750.     cp -af /lib/modules/2.0.21/net/3c59x.o $DIR_TARGET/lib/modules/2.0.21/net
  6751.   fi
  6752. }
  6753.  
  6754. Fix_DEV()
  6755. {
  6756.     if [ ! -b $DIR_TARGET/dev/cdu31a ]; then
  6757.         if [ -b $DIR_TARGET/dev/sonycd ]; then
  6758.             cp -a $DIR_TARGET/dev/sonycd $DIR_TARGET/dev/cdu31a
  6759.         fi
  6760.     fi
  6761. }
  6762.  
  6763. Fix_runlevel()
  6764. {
  6765.     # With COL 2.2 the default runlevel is 5, but with the lisa install
  6766.     # X is not configured yet, so we must set the default runlevel to 3
  6767.     sed 's/^id:5:initdefault:/id:3:initdefault:/' $DIR_TARGET/etc/inittab > $DIR_TARGET/etc/inittab.tmp
  6768.     mv $DIR_TARGET/etc/inittab.tmp $DIR_TARGET/etc/inittab
  6769.     chmod 644 $DIR_TARGET/etc/inittab
  6770. }
  6771.  
  6772. Fix_shadow22()
  6773. {
  6774.     sed 's/:0::7:7::/:0:365:7:7::/' $DIR_TARGET/etc/shadow > $DIR_TARGET/etc/shadow.tmp
  6775.     mv $DIR_TARGET/etc/shadow.tmp $DIR_TARGET/etc/shadow
  6776.     chmod 600 $DIR_TARGET/etc/shadow
  6777. }
  6778.  
  6779. Do_Fixes_After_First_Config()
  6780. {
  6781.     Info ":INFO_COPYING_FILES_TO_TARGET:"
  6782.     Set_LISA_CONF
  6783.     Transfer_dev_symlinks
  6784.     Fix_Missing_Root
  6785.     Fix_Broken_Insmod
  6786.     mkdir -p /etc/sysconfig
  6787.     mkdir -p /etc/sysconfig/network-scripts
  6788.     mkdir -p /etc/rc.d/init.d
  6789.     Set_etc_HOSTNAME
  6790.     Set_keyboard
  6791.     Set_pcmcia
  6792.     Set_network
  6793.     Set_ifcfg eth0
  6794.     Set_ifcfg tr0
  6795.     # Fix_conf_getty
  6796.     Fix_etc_fstab
  6797.     Set_Resolver
  6798.     Fix_faked_lib_versions
  6799.     Fix_Obsolete_Progs
  6800.     Fix_ldconfig
  6801.     if [ "$CND10_MODE" = "true" ]; then
  6802.         Fix_freeramdisk
  6803.         Fix_rc_sysinit
  6804.         Fix_procps
  6805.     fi
  6806.     Fix_news
  6807.     Fix_3c59x
  6808.     Fix_DEV
  6809.     Do_Setup_teTeX
  6810.     Do_Setup_locate
  6811.     Fix_tmp_area
  6812.     Fix_uucp
  6813.     Fix_runlevel
  6814.     Fix_shadow22
  6815.     Finish_unconfigured_sh
  6816. }
  6817.  
  6818.  
  6819. Fix_tmp_area()
  6820. {
  6821.   mkdir -p $DIR_TARGET/tmp
  6822.   chmod 1777 $DIR_TARGET/tmp
  6823.   Debug "Fixing mode of tmp area"
  6824. }
  6825.  
  6826. Create_fsstnd()
  6827. {
  6828.   # FIXME: should be created by a fsstnd pkg
  6829.   mkdir -p $DIR_TARGET/tmp
  6830.   chmod 1777 $DIR_TARGET/tmp
  6831.   mkdir -p $DIR_TARGET/boot
  6832.   mkdir -p $DIR_TARGET/etc
  6833.   mkdir -p $DIR_TARGET/mnt
  6834.   mkdir -p $DIR_TARGET/usr
  6835.   ( cd $DIR_TARGET/usr ; ln -sf ../var/spool spool )
  6836.   mkdir -p $DIR_TARGET/var/spool/lpd
  6837.   mkdir -p $DIR_TARGET/var/spool/mail
  6838.   mkdir -p $DIR_TARGET/var/spool/news
  6839.   mkdir -p $DIR_TARGET/var/spool/uucp
  6840. }
  6841.  
  6842. Transfer_LISA()
  6843. {
  6844.   local i
  6845.   local binaries_from_floppy
  6846.  
  6847.   if [ "$CND10_MODE" = "true" ]; then
  6848.     binaries_from_floppy="box build_menu db_printf do_calc do_echo do_netcalc do_quote filesize get_info get_key get_val hilfe lisa prep_use set_val sysinfo rpmq"
  6849.   else
  6850.     binaries_from_floppy="filesize hilfe lisa prep_use"
  6851.   fi
  6852.  
  6853.  
  6854.   # init LISA tmp area
  6855.   mkdir -p $DIR_TARGET/tmp/LST
  6856.   chmod 1777 $DIR_TARGET/tmp
  6857.  
  6858.   # init LISA install area
  6859.   # be backward compatible to old LST install directory
  6860.   mkdir -p $DIR_TARGET/var/lib/LST
  6861.   mkdir -p $DIR_TARGET/var/lib/LST/log
  6862.   mkdir -p $DIR_TARGET/var/lib/LST/analyse
  6863.   rm -fr $DIR_TARGET/install
  6864.   ln -sf var/lib/LST $DIR_TARGET/install
  6865.   echo "$CONF_LST_VERSION" > $DIR_TARGET/install/BASEVERSION
  6866.   if [ -d /var/lib/LST ]; then
  6867.     cp -aR /var/lib/LST $DIR_TARGET/var/lib
  6868.   fi
  6869.  
  6870.   # copy LISA doc area
  6871.   mkdir -p $DIR_TARGET/usr/doc/LST
  6872.   cp -aR /floppy/usr/doc/LST/* /usr/doc/LST/* /source/doc/LST/* $DIR_TARGET/usr/doc/LST
  6873.   gzip -df $DIR_TARGET/usr/doc/LST/*.gz
  6874.   if [ "$INSTALL_MODE" = "LST" ]; then
  6875.     # to make sure they are read ;-)
  6876.     for i in COPYING CREDITS README.1st ; do
  6877.       if [ -f $DIR_TARGET/usr/doc/LST/$i ]; then
  6878.         ln -s usr/doc/LST/$i $DIR_TARGET/$i
  6879.       fi
  6880.     done
  6881.   fi
  6882.  
  6883.   # copy LISA lib area
  6884.   mkdir -p $DIR_TARGET/usr/lib/LST
  6885.   cp -a /usr/lib/LST/smarties $DIR_TARGET/usr/lib/LST
  6886.   cp -a /usr/lib/LST/IDENTIFY $DIR_TARGET/usr/lib/LST/IDENTIFY.root
  6887.   if [ -f /floppy/IDENTIFY ]; then
  6888.     cp -a /floppy/IDENTIFY $DIR_TARGET/usr/lib/LST/IDENTIFY.boot
  6889.   fi
  6890.   echo "`uname -a`" > $DIR_TARGET/usr/lib/LST/IDENTIFY.kernel
  6891.   for i in libLSTall meta.db pkgs.db pkgs.idx ; do
  6892.     if [ -f /usr/lib/LST/$i.gz ]; then
  6893.       cp -a /usr/lib/LST/$i.gz $DIR_TARGET/usr/lib/LST/$i.gz
  6894.       gzip -df $DIR_TARGET/usr/lib/LST/$i.gz
  6895.     elif [ -f /usr/lib/LST/$i ]; then
  6896.       cp -a /usr/lib/LST/$i $DIR_TARGET/usr/lib/LST/$i
  6897.     fi
  6898.   done
  6899.   cp -a /usr/lib/LST/libLSTtext $DIR_TARGET/usr/lib/LST/libLSTtext
  6900.  
  6901.   # copy LISA binary files from floppy to target
  6902.   mkdir -p $DIR_TARGET/bin
  6903.   # FIXME: no binaries at all should be copied from the install floppy
  6904.   for i in $binaries_from_floppy ; do
  6905.     if [ -f /bin/$i.gz ]; then
  6906.       cp -a /bin/$i.gz $DIR_TARGET/bin
  6907.       gzip -df $DIR_TARGET/bin/$i.gz
  6908.     elif [ -f /bin/$i ]; then
  6909.       cp -a /bin/$i $DIR_TARGET/bin
  6910.     fi
  6911.   done
  6912.   ( cd $DIR_TARGET/bin ; ln -sf prep_use end_use )
  6913.   ( cd $DIR_TARGET/bin ; ln -sf prep_use not_use )
  6914.   ( cd $DIR_TARGET/bin ; ln -sf prep_use show_use )
  6915.   ( cd $DIR_TARGET/bin ; ln -sf lisa sysinstall )
  6916.   ( cd $DIR_TARGET/bin ; ln -sf lisa syssetup )
  6917.   ( cd $DIR_TARGET/bin ; ln -sf lisa netsetup )
  6918.  
  6919.   # copy LISA config files
  6920.   Set_LISA_CONF
  6921. }
  6922.  
  6923. Transfer_RPM()
  6924. {
  6925.   # init RPM area
  6926.   mkdir -p $DIR_TARGET/var/lib/rpm
  6927.   mkdir -p /var/lib
  6928.   ln -sf $DIR_TARGET/var/lib/rpm /var/lib/rpm
  6929. }
  6930.  
  6931. Transfer_kernel()
  6932. {
  6933.   local i
  6934.   local kernel
  6935.  
  6936.   # copy kernel
  6937.   for i in $DIR_TARGET/floppy/vmlinuz* ; do
  6938.     if [ -f $i ]; then
  6939.       kernel=`basename $i`
  6940.       ln -f $i $DIR_TARGET/$kernel
  6941.     fi
  6942.   done
  6943.   # copy WHATSIN files
  6944.   mkdir -p $DIR_TARGET/boot
  6945.   for i in $DIR_TARGET/floppy/boot/WHATSIN* ; do
  6946.     if [ -f $i ]; then
  6947.       kernel=`basename $i`
  6948.       ln -f $i $DIR_TARGET/boot/$kernel
  6949.     fi
  6950.   done
  6951. }
  6952.  
  6953. Transfer_modules()
  6954. {
  6955.   local i
  6956.  
  6957.   # copy modules
  6958.   mkdir -p $DIR_TARGET/lib/modules
  6959.   cp -aR /floppy/lib/modules/* /lib/modules/* $DIR_TARGET/lib/modules
  6960.   for i in $DIR_TARGET/lib/modules/`uname -r`/*/*.o.gz ; do
  6961.     if [ -f $i ]; then
  6962.       gzip -df $i
  6963.     fi
  6964.   done
  6965. }
  6966.  
  6967. Delete_unused_modules()
  6968. {
  6969.     local i
  6970.     local modpath=/lib/modules/`uname -r`
  6971.  
  6972.     for i in $modpath/*/*.gz ; do
  6973.         rm -f $i
  6974.     done
  6975. }
  6976.  
  6977. Do_Switch_Log_Area()
  6978. {
  6979.     Do_Log -f $FILE_LOG_HISTORY "`date` $LOGNAME: Moving log area to $DIR_TARGET"
  6980.     mkdir -p $DIR_TARGET/var/adm
  6981.     cp -aR /var/adm/LST $DIR_TARGET/var/adm
  6982.     rm -fr /var/adm/LST
  6983.     ln -s $DIR_TARGET/var/adm/LST /var/adm/LST
  6984. }
  6985.  
  6986. Transfer_root_floppy()
  6987. {
  6988.     local i
  6989.     local kernel=
  6990.     local prefix=
  6991.  
  6992.     # copy LILO files
  6993.     mkdir -p $DIR_TARGET/floppy/boot
  6994.     for i in any_b.b any_d.b boot.b chain.b message os2_d.b ; do
  6995.         if [ -f /boot/$i ]; then
  6996.             cp -a /boot/$i $DIR_TARGET/floppy/boot
  6997.         fi
  6998.         if [ -f /floppy/boot/$i ]; then
  6999.             cp -a /floppy/boot/$i $DIR_TARGET/floppy/boot
  7000.         fi
  7001.     done
  7002.  
  7003.     mkdir -p $DIR_TARGET/floppy/sbin
  7004.     for i in activate lilo sysinstall mkfs.minix ; do
  7005.         if [ -f /sbin/$i.gz ]; then
  7006.             cp -a /sbin/$i.gz $DIR_TARGET/floppy/sbin
  7007.             gunzip -f $DIR_TARGET/floppy/sbin/$i.gz
  7008.         fi
  7009.     done
  7010.  
  7011.     mkdir -p $DIR_TARGET/floppy/etc
  7012.     if [ -f /etc/lilo.conf.in ]; then
  7013.         cp -a /etc/lilo.conf.in $DIR_TARGET/floppy/etc/lilo.conf
  7014.     fi
  7015.  
  7016.     # copy kernel
  7017.     for i in /vmlinuz* /floppy/vmlinuz* ; do
  7018.         if [ -f $i ]; then
  7019.             kernel=`basename $i`
  7020.             cp -a $i $DIR_TARGET/floppy/$kernel
  7021.             rdev $DIR_TARGET/floppy/$kernel $CONF_INSTALL_ROOT
  7022.             rdev -r $DIR_TARGET/floppy/$kernel 0
  7023.             rdev -R $DIR_TARGET/floppy/$kernel 1
  7024.             if [ "$DIR_TARGET" = "/root/linux" ]; then
  7025.                 rdev -R $DIR_TARGET/floppy/$kernel 0
  7026.             fi
  7027.         fi
  7028.     done
  7029.  
  7030.     if [ -f /boot/WHATSIN* ]; then
  7031.         cp -a /boot/WHATSIN* $DIR_TARGET/floppy/boot
  7032.     fi
  7033.     if [ -f /floppy/boot/WHATSIN* ]; then
  7034.         cp -a /floppy/boot/WHATSIN* $DIR_TARGET/floppy/boot
  7035.     fi
  7036.  
  7037.     # creating device files
  7038.     mkdir -p $DIR_TARGET/floppy/dev
  7039.     prefix=$DIR_TARGET/floppy/dev/
  7040.     mknod -m 644 ${prefix}fd0 b 2 0
  7041.     mknod -m 644 ${prefix}fd0h1200 b 2 8
  7042.     mknod -m 644 ${prefix}fd0H1440 b 2 28
  7043.     mknod -m 644 ${prefix}fd1 b 2 1
  7044.     mknod -m 644 ${prefix}fd1h1200 b 2 9
  7045.     mknod -m 644 ${prefix}fd1H1440 b 2 29
  7046.     # chgrp root.disk ${prefix}fd*
  7047. }
  7048.  
  7049. Fix_apache()
  7050. {
  7051.     # apache-httpd version 1.1.1-10 is broken and needs symlinks
  7052.     if [ -n "`fgrep apache-httpd $FILE_PKGS_DATA | fgrep '1.1.1-10'`" ]; then
  7053.         Debug "fixing broken apache-httpd-1.1.1-10 package..."
  7054.         mkdir -p $DIR_TARGET/home/httpd
  7055.         ln -s apache/html $DIR_TARGET/home/httpd/html
  7056.         ln -s apache/cgi-bin $DIR_TARGET/home/httpd/cgi-bin
  7057.         ln -s apache/icons $DIR_TARGET/home/httpd/icons
  7058.     fi
  7059. }
  7060.  
  7061. Fix_useradd()
  7062. {
  7063.     # lisa-2.2-3 contains a broken useradd (creates "*" passwd entries)
  7064.     if [ -n "`fgrep lisa $FILE_PKGS_DATA | fgrep '2.2-3'`" ]; then
  7065.         if [ -r /usr/sbin/useradd.ELF.gz ]; then
  7066.             Debug "fixing broken lisa-2.2-3 package..."
  7067.             cp -af /usr/sbin/useradd.ELF.gz $DIR_TARGET/usr/sbin/useradd.gz
  7068.             gzip -df $DIR_TARGET/usr/sbin/useradd.gz
  7069.             chmod 755 $DIR_TARGET/usr/sbin/useradd
  7070.         fi
  7071.     fi
  7072. }
  7073.  
  7074. Fix_log_permissions()
  7075. {
  7076.     touch $DIR_TARGET/var/log/messages
  7077.     chmod 600 $DIR_TARGET/var/log/messages
  7078.     touch $DIR_TARGET/var/log/secure
  7079.     chmod 600 $DIR_TARGET/var/log/secure
  7080. }
  7081.  
  7082. Fix_rc_modules()
  7083. {
  7084.     sed '/^    insmod/s/\"//g' < $DIR_TARGET/etc/rc.d/rc.modules > $DIR_TARGET/etc/rc.d/rc.modules.tmp
  7085.     chmod 755 $DIR_TARGET/etc/rc.d/rc.modules.tmp
  7086.     mv $DIR_TARGET/etc/rc.d/rc.modules.tmp $DIR_TARGET/etc/rc.d/rc.modules
  7087. }
  7088.  
  7089. Do_Init_Target()
  7090. {
  7091.     local i
  7092.     local kernel=
  7093.     local prefix=
  7094.  
  7095.     Info ":INFO_COPYING_FILES_TO_TARGET:"
  7096.     Create_fsstnd
  7097.     Transfer_LISA
  7098.     Transfer_RPM
  7099.     Transfer_root_floppy
  7100.     Transfer_kernel
  7101.     Transfer_modules
  7102.     Set_modules_autoload
  7103.     Fix_12_Alpha target_mounted
  7104.     Set_initrd
  7105.     # FIXME: for debugging only
  7106.     # trigger a copy of the initrd we used for install under /var/tmp/initrd
  7107.     # touch /save_initrd
  7108.     # trigger a initrd umount and freeramdisk in rc.boot
  7109.     touch /free_initrd
  7110.     Set_message
  7111.     Fix_lilo
  7112.     Fix_daemons
  7113.     Fix_apache
  7114.     # FIXME: need better method to find initrd
  7115.     if [ "`uname -r`" != "1.2.13" ]; then
  7116.         mkdir -p $DIR_TARGET/initrd
  7117.         Set_Real_Root $CONF_INSTALL_ROOT
  7118.     fi
  7119.     # this is to support RPM 2.2.x
  7120.     mkdir -p $DIR_TARGET/etc
  7121.     if [ "$DIR_TARGET" != "/" ]; then
  7122.         cp -a /etc/passwd $DIR_TARGET/etc/passwd
  7123.         cp -a /etc/group $DIR_TARGET/etc/group
  7124.         # we bring a rpmrc for 2.2 with us on the floppy
  7125.         # check if we have for newer ones
  7126.         if [ -f /source/lib/rpmrc-2.5 ]; then
  7127.             ln -s /source/lib/rpmrc-2.5 /usr/lib/rpmrc-2.5
  7128.         elif [ -f /source/lib/rpmrc-2.4 ]; then
  7129.             ln -s /source/lib/rpmrc-2.4 /usr/lib/rpmrc-2.4
  7130.         fi
  7131.     fi
  7132.     ROOT_INITIALIZED=1
  7133.     return 0
  7134. }
  7135.  
  7136. Fix_i386_RPMS()
  7137. {
  7138.     if [ "$INSTALL_MODE" != "OpenLinux" ]; then
  7139.         mkdir -p $DIR_TARGET/usr/src/redhat/RPMS/i386
  7140.     fi
  7141. }
  7142.  
  7143. Fix_SuperProbe()
  7144. {
  7145.     # security fix
  7146.     chmod -s $DIR_TARGET/usr/X11R6/bin/SuperProbe
  7147. }
  7148.  
  7149. Fix_root_dotfiles()
  7150. {
  7151.     mkdir -p $DIR_TARGET/root
  7152.     cp -aR $DIR_TARGET/etc/skel/.??* $DIR_TARGET/root
  7153. }
  7154.  
  7155. Fix_etc_login_defs()
  7156. {
  7157.     if [ -f $DIR_TARGET/etc/login.defs ]; then
  7158.         sed 's/^HOME        \/home/HOME        \/home\/%s/' $DIR_TARGET/etc/login.defs > $DIR_TARGET/etc/login.defs.tmp
  7159.         mv $DIR_TARGET/etc/login.defs.tmp $DIR_TARGET/etc/login.defs
  7160.         chmod 640 $DIR_TARGET/etc/login.defs
  7161.     fi
  7162. }
  7163.  
  7164. Fix_usr_info_dir_gz()
  7165. {
  7166.     # this file is not necessary and makes xeamcs really unhappy, so remove it
  7167.     if [ -f $DIR_TARGET/usr/info/dir.gz ]; then
  7168.         rm -f $DIR_TARGET/usr/info/dir.gz
  7169.     fi
  7170. }
  7171.  
  7172. Do_Fixes_After_Pkg_Install()
  7173. {
  7174.     Fix_sendmail_start
  7175.     Fix_httpd_start
  7176.     Fix_i386_RPMS
  7177.     Fix_SuperProbe
  7178.     Fix_rc_modules
  7179.     Fix_useradd
  7180.     Fix_log_permissions
  7181.     Fix_root_dotfiles
  7182.     Fix_etc_login_defs
  7183.     Fix_usr_info_dir_gz
  7184. }
  7185.  
  7186. # libLSTmodule - module handling library shared between several scripts
  7187. #
  7188. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  7189. #
  7190.  
  7191.  
  7192. List_MODULES_LOADED()
  7193. {
  7194.     lsmod | fgrep -v "#pages" 
  7195. }
  7196.  
  7197. Build_MODULES_LOADED()
  7198. {
  7199.     List_MODULES_LOADED | do_quote
  7200. }
  7201.  
  7202. List_MODULES_AVAILABLE()
  7203. {
  7204.     local module=
  7205.  
  7206.     for module in /floppy/lib/modules/`uname -r`/*/*.o ; do
  7207.         if [ -f $module ]; then
  7208.             echo "`basename $module .o`"
  7209.         fi
  7210.     done
  7211.     for module in /floppy/lib/modules/`uname -r`/*/*.o.gz ; do
  7212.         if [ -f $module ]; then
  7213.             echo "`basename $module .o.gz`"
  7214.         fi
  7215.     done
  7216.     for module in /lib/modules/`uname -r`/*/*.o ; do
  7217.         if [ -f $module ]; then
  7218.             echo "`basename $module .o`"
  7219.         fi
  7220.     done
  7221.     for module in /lib/modules/`uname -r`/*/*.o.gz ; do
  7222.         if [ -f $module ]; then
  7223.             echo "`basename $module .o.gz`"
  7224.         fi
  7225.     done
  7226. }
  7227.  
  7228. Build_MODULES_AVAILABLE()
  7229. {
  7230.     List_MODULES_AVAILABLE | do_quote
  7231. }
  7232.  
  7233. Menu_Module_Load()
  7234. {
  7235.     Choose --menutitle ":INFO_MODULES_LOADED_MENUTITLE:" --build Build_MODULES_AVAILABLE MODULE_LOAD || return 1
  7236.     if [ -z "$ANSWER" ]; then
  7237.         Error "no module specified"
  7238.         return 1
  7239.     fi
  7240.     Do_Load_Module "$ANSWER" || return 1
  7241.     return 0
  7242. }
  7243.  
  7244. Menu_Module_Remove()
  7245. {
  7246.     Choose --menutitle ":INFO_MODULES_LOADED_MENUTITLE:" --build Build_MODULES_LOADED MODULE_REMOVE || return 1
  7247.     if [ -z "$ANSWER" ]; then
  7248.         Error "no module specified"
  7249.         return 1
  7250.     fi
  7251.     rmmod $ANSWER || return 1
  7252.     return 0
  7253. }
  7254.  
  7255. Menu_Module_Show_Loaded()
  7256. {
  7257.     List_MODULES_LOADED > $FILE_TMP_MSG 2> $FILE_TMP_ERR
  7258.     if [ -s $FILE_TMP_ERR ]; then
  7259.         Error --file $FILE_TMP_ERR
  7260.         return 1
  7261.     fi
  7262.     if [ ! -s $FILE_TMP_MSG ]; then
  7263.         Msg ":INFO_NO_MODULES_LOADED:"
  7264.     else
  7265.         $CMD_BOX --help ":HELP_MODULES:" \
  7266. --title ":INFO_MODULES_LOADED_TITLE:" \
  7267. --menutitle ":INFO_MODULES_LOADED_MENUTITLE:" \
  7268. --text ":INFO_MODULES_LOADED_TEXT:" --browse $FILE_TMP_MSG
  7269.     fi
  7270. }
  7271.  
  7272. Menu_Module_Show_Available()
  7273. {
  7274.     List_MODULES_AVAILABLE > $FILE_TMP_MSG 2> $FILE_TMP_ERR
  7275.     if [ -s $FILE_TMP_ERR ]; then
  7276.         Error --file $FILE_TMP_ERR
  7277.         return 1
  7278.     fi
  7279.     if [ ! -s $FILE_TMP_MSG ]; then
  7280.         Msg ":INFO_NO_MODULES_AVAILABLE:"
  7281.     else
  7282.         $CMD_BOX --help ":HELP_MODULES:" \
  7283. --title ":INFO_MODULES_AVAILABLE_TITLE:" \
  7284. --text ":INFO_MODULES_AVAILABLE_TEXT:" --browse $FILE_TMP_MSG
  7285.     fi
  7286. }
  7287.  
  7288. Do_Load_Driver()
  7289. {
  7290.     local present=0
  7291.     local test_only=
  7292.     local silent_flag=
  7293.     local module_name=
  7294.     local module_type=
  7295.  
  7296.     if [ $# -gt 0 -a "$1" = '--test' ]; then
  7297.         test_only=true        
  7298.         shift 1
  7299.     fi
  7300.  
  7301.     if [ $# -ne 2 ]; then
  7302.         Panic ":ERR_WRONG_NUM_OF_ARGS: ($#)" || return 1
  7303.     fi
  7304.  
  7305.     case $1 in
  7306.     # filesystems
  7307.     filesystem)
  7308.         module_type=fs
  7309.         silent_flag='--silent'
  7310.         sysinfo --var --kernel 2>&1 >/dev/null | fgrep "INFO_FILESYSTEMS" > $FILE_TMP_MSG
  7311.         fgrep ":$2:" $FILE_TMP_MSG >/dev/null && return 0
  7312.         case $2 in
  7313.         nfs|hpfs|msdos|umsdos)
  7314.             module_name="$2"
  7315.             ;;
  7316.         iso9660)
  7317.             module_name="isofs"
  7318.             ;;
  7319.         esac
  7320.         ;;
  7321.     # CDROMs
  7322.     cdrom)
  7323.         module_type=misc
  7324.         sysinfo >/dev/null --var --cdrom 2> $FILE_TMP_MSG
  7325.         sed 's:/dev/sr:/dev/scd:' < $FILE_TMP_MSG |
  7326.             fgrep ":$2:" >/dev/null
  7327.         if [ $? -eq 0 ]; then
  7328.             return 0
  7329.         fi
  7330.         case $2 in
  7331.         /dev/arcd)
  7332.             module_name="arcd"
  7333.             ;;
  7334.         /dev/aztcd)
  7335.             module_name="aztcd"
  7336.             ;;
  7337.         /dev/bpcd)
  7338.             module_name="bpcd"
  7339.             ;;
  7340.         /dev/bpmcd)
  7341.             module_name="bpmcd"
  7342.             ;;
  7343.         /dev/cdu31a)
  7344.             module_name="cdu31a"
  7345.             ;;
  7346.         /dev/cdu535)
  7347.             module_name="sonycd535"
  7348.             ;;
  7349.         /dev/cm206cd)
  7350.             module_name="cm206"
  7351.             ;;
  7352.         /dev/dscd)
  7353.             module_name="dscd"
  7354.             ;;
  7355.         /dev/epcd)
  7356.             module_name="epcd"
  7357.             ;;
  7358.         /dev/gscd)
  7359.             module_name="gscd"
  7360.             ;;
  7361.         /dev/kicd)
  7362.             module_name="kicd"
  7363.             ;;
  7364.         /dev/oicd)
  7365.             module_name="oicd"
  7366.             ;;
  7367.         /dev/optcd)
  7368.             module_name="optcd"
  7369.             ;;
  7370.         /dev/mcd)
  7371.             module_name="mcd"
  7372.             ;;
  7373.         /dev/mcdx)
  7374.             module_name="mcdx"
  7375.             ;;
  7376.         /dev/pwcd)
  7377.             module_name="pwcd"
  7378.             ;;
  7379.         /dev/sbpcd)
  7380.             module_name="sbpcd"
  7381.             ;;
  7382.         /dev/sbpcd0)
  7383.             module_name="sbpcd"
  7384.             ;;
  7385.         /dev/sjcd)
  7386.             module_name="sjcd"
  7387.             ;;
  7388.         /dev/sonycd)
  7389.             module_name="cdu31a"
  7390.             ;;
  7391.         *)
  7392.             module_name=""
  7393.             ;;
  7394.         esac
  7395.         ;;
  7396.     ether)
  7397.         module_type=net
  7398.         silent_flag='--silent'
  7399.         sysinfo >/dev/null --var --ether 2> $FILE_TMP_MSG
  7400.         fgrep ":$2:" $FILE_TMP_MSG >/dev/null && return 0
  7401.         return 1
  7402.         ;;
  7403.     esac
  7404.     if [ -n "$test_only" ]; then
  7405.         return 1
  7406.     fi
  7407.  
  7408.     if [ -z "$module_name" ]; then
  7409.         if [ "$1" = "cdrom" ]; then
  7410.             echo "$2" | fgrep /dev/hd >/dev/null 2>&1
  7411.             if [ $? -eq 0 ]; then
  7412.                 # has to be an ATAPI CDROM...
  7413.                 return 0
  7414.             fi
  7415.         fi
  7416.         $CMD_BOX --msg "$2 ; :ERR_NO_DEVICE_AND_NO_MODULE:"
  7417.         return 1
  7418.     else
  7419.         Do_Load_Module $silent_flag $module_name $module_type
  7420.         retval=$?
  7421.         end_use /lib/modules/`uname -r`/$module_type/$module_name.o
  7422.     fi
  7423.     return $retval
  7424. }
  7425.  
  7426. Do_Load_Module()
  7427. {
  7428.   local silent_flag=
  7429.   local modpath=
  7430.   local subpath=
  7431.   local module=
  7432.   local modparam=
  7433.   local param=
  7434.  
  7435.   if [ $# -gt 0 -a "$1" = '--silent' ]; then
  7436.     silent_flag=true
  7437.     shift 1
  7438.   fi
  7439.   if [ $# -gt 1 -a "$1" = '--param' ]; then
  7440.     param="$2"
  7441.     shift 2
  7442.   fi
  7443.  
  7444.   if [ $# -lt 1 ]; then Panic ":ERR_INVALID_PARAMS:" ; fi
  7445.  
  7446.   # check whether it's already loaded
  7447.   lsmod | sed -n "/^$1/p" > $FILE_TMP_ANSWER
  7448.   if [ -s $FILE_TMP_ANSWER ]; then
  7449.     Debug "Module $1 seems to be loaded..."
  7450.     return 0
  7451.   else
  7452.     Debug "Module $1 is not loaded..."
  7453.   fi
  7454.  
  7455.   if [ -n "$param" ]; then
  7456.     modparam="$param"
  7457.   else
  7458.     # initialize with boot params
  7459.     if [ -s $FILE_BOOT_PARAMS ]; then
  7460.       Debug "Search for boot param <$1> in <$FILE_BOOT_PARAMS>..."
  7461.       sed -n "/^$1=/p" $FILE_BOOT_PARAMS > $FILE_TMP_ANSWER
  7462.       modparam="`cat $FILE_TMP_ANSWER`"
  7463.       Debug "found boot param <$modparam>"
  7464.     fi
  7465.   fi
  7466.  
  7467.   # check whether it's available 
  7468.   modpath=/lib/modules/`uname -r`
  7469.   for subpath in $2 block cdrom fs ipv4 misc net pcmcia scsi ; do
  7470.     module="$modpath/$subpath/$1.o"
  7471.     if [ -s $module ]; then
  7472.       break
  7473.     elif [ -s ${module}.gz ]; then
  7474.       gzip -df ${module}.gz && break
  7475.     elif [ -s /source${module} ]; then
  7476.       ln -sf /source${module} $module && break
  7477.     elif [ -s /floppy${module}.gz ]; then
  7478.       gzip -dc /floppy${module}.gz > $module && break
  7479.     fi
  7480.     module=
  7481.   done 
  7482.  
  7483.   if [ -z "$module" ]; then
  7484.     $CMD_BOX --msg "module $1.o ; :ERR_MODULE_NOT_AVAILABLE:"
  7485.     return 1
  7486.   fi 
  7487.  
  7488.   while [ 1 ]; do
  7489.     # dirty hack to adjust symbol names used for modules
  7490.     echo $modparam | sed '{
  7491.     s/^cm206=/cm206_base=/
  7492.     s/^gscd=/gscd_port=/
  7493.     s/^sonycd535=/sony535_cd_base_io=/
  7494.     }' > $FILE_TMP_ANSWER
  7495.     modparam="`cat $FILE_TMP_ANSWER`"
  7496.     if [ -z "$silent_flag" ]; then
  7497.       Info "module $1.o ; :INFO_MODULE_LOADING:"
  7498.     fi
  7499.     insmod $module $modparam >$FILE_TMP_ERR 2>&1 && break
  7500.     $CMD_BOX --msg "module $1.o ; :ERR_MODULE_LOADING_FAILED:"
  7501.     rmmod $1 >/dev/null 2>&1
  7502.     Ask_String BOOT_PARAM $modparam || return 1
  7503.     modparam="$ANSWER"
  7504.     if [ -z "$modparam" ]; then return 1 ; fi
  7505.   done
  7506.   echo "$1" >> /tmp/modules
  7507.   mkdir -p /etc/modules/options
  7508.   if [ -n "$modparam" ]; then
  7509.     echo "$modparam" > /etc/modules/options/$1
  7510.   else
  7511.     rm -f /etc/modules/options/$1
  7512.   fi
  7513.   return 0
  7514. }
  7515.  
  7516. Do_Unload_Module()
  7517. {
  7518.   local f_name=Do_Unload_Module
  7519.   local f_args=1 # (modulename) ->
  7520.  
  7521.   Check_Args $f_name $f_args $# "$@" || return 255
  7522.   Debug "unloading module $1 ..."
  7523.   Info "module $1.o ; :INFO_MODULE_UNLOADING:"
  7524.   rmmod $1 && return 0
  7525.   return 1
  7526. }
  7527.  
  7528. # libLSTnet - network handling library shared between several scripts
  7529. #
  7530. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  7531. #
  7532.  
  7533. Do_Ifcfg()
  7534. {
  7535.     local interface="$1"
  7536.     local action="$2"
  7537.  
  7538.     Debug "Do_Ifcfg called with <$1> <$2>"
  7539.     case $interface in
  7540.     lo)
  7541.         Do_Ifcfg_lo $action
  7542.         ;;
  7543.     eth0)
  7544.         Do_Ifcfg_eth 0 $action
  7545.         ;;
  7546.     eth1)
  7547.         Do_Ifcfg_eth 1 $action
  7548.         ;;
  7549.     tr0)
  7550.         Do_Ifcfg_tr 0 $action
  7551.         ;;
  7552.     plip0)
  7553.         Do_Ifcfg_plip 0 $action
  7554.         ;;
  7555.     plip1)
  7556.         Do_Ifcfg_plip 1 $action
  7557.         ;;
  7558.     plip2)
  7559.         Do_Ifcfg_plip 2 $action
  7560.         ;;
  7561.     default)
  7562.         Do_Ifcfg_default $action
  7563.         ;;
  7564.     esac
  7565. }
  7566.  
  7567. Do_Ifcfg_default()
  7568. {
  7569.     local router="`Get_Val CONF_ROUTER1_IP`"
  7570.  
  7571.     # route del default
  7572.     if [ "$1" = "up" ]; then
  7573.         if [ -n "$router" ]; then
  7574.             Debug "route add default gw $router"
  7575.             route add default gw $router
  7576.         fi
  7577.     fi
  7578. }
  7579.  
  7580. Do_Ifcfg_plip()
  7581. {
  7582.     local num="$1"
  7583.     local plipx="plip${num}"
  7584.     local ip="`Get_Val CONF_${plipx}_IP`"
  7585.     local remote_ip="`Get_Val CONF_${plipx}_REMOTE_IP`"
  7586.  
  7587.     Debug "Debug: Do_Ifcfg_plip $1 $2"
  7588.     Debug "Debug: net = <$net>"
  7589.     # ifconfig $plipx down
  7590.     # route del -net $net
  7591.     if [ "$2" = "up" ]; then
  7592.         Debug "bringing up interface"
  7593.         Debug "ifconfig $plipx $ip pointopoint $remote_ip"
  7594.         ifconfig $plipx $ip pointopoint $remote_ip
  7595.         Debug "route add -host $remote_ip gw $ip"
  7596.         route add -host $remote_ip gw $ip
  7597.     fi
  7598. }
  7599.  
  7600. Do_Ifcfg_tr()
  7601. {
  7602.     local num="$1"
  7603.     local trx="tr${num}"
  7604.     local ip="`Get_Val CONF_${trx}_IP`"
  7605.     local net="`Get_Val CONF_${trx}_NET`"
  7606.     local mask="`Get_Val CONF_${trx}_MASK`"
  7607.     local bcast="`Get_Val CONF_${trx}_BCAST`"
  7608.  
  7609.     Debug "Debug: Do_Ifcfg_tr $1 $2"
  7610.     Debug "Debug: net = <$net>"
  7611.     # ifconfig $trx down
  7612.     # route del -net $net
  7613.     if [ "$2" = "up" ]; then
  7614.         Debug "bringing up interface $trx"
  7615.         Debug "ifconfig $trx $ip netmask $mask broadcast $bcast"
  7616.         ifconfig $trx $ip netmask $mask broadcast $bcast
  7617.         Debug "route add -net $net"
  7618.         route add -net $net
  7619.     fi
  7620. }
  7621.  
  7622. Do_Ifcfg_eth()
  7623. {
  7624.     local num="$1"
  7625.     local ethx="eth${num}"
  7626.     local ip="`Get_Val CONF_${ethx}_IP`"
  7627.     local net="`Get_Val CONF_${ethx}_NET`"
  7628.     local mask="`Get_Val CONF_${ethx}_MASK`"
  7629.     local bcast="`Get_Val CONF_${ethx}_BCAST`"
  7630.  
  7631.     Debug "Debug: Do_Ifcfg_eth $1 $2"
  7632.     Debug "Debug: net = <$net>"
  7633.     # ifconfig $ethx down
  7634.     # route del -net $net
  7635.     if [ "$2" = "up" ]; then
  7636.         Debug "bringing up interface $ethx"
  7637.         Debug "ifconfig $ethx $ip netmask $mask broadcast $bcast"
  7638.         ifconfig $ethx $ip netmask $mask broadcast $bcast
  7639.         Debug "route add -net $net"
  7640.         route add -net $net
  7641.     fi
  7642. }
  7643.  
  7644. Do_Ifcfg_lo()
  7645. {
  7646.     # ifconfig lo down
  7647.     # route del -net 127.0.0.0
  7648.     if [ "$1" = "up" ]; then
  7649.         Debug "ifconfig lo 127.0.0.1"
  7650.         ifconfig lo 127.0.0.1
  7651.         Debug "route add -net 127.0.0.0"
  7652.         route add -net 127.0.0.0
  7653.     fi
  7654. }
  7655.  
  7656. Menu_Config_Nethost()
  7657. {
  7658.     Menu_Config_FQ_Name || return 1
  7659.     Do_Ifcfg lo up
  7660.     Menu_Config_Netdev || return 1
  7661.     Get_netprobe_Info
  7662.     Menu_Config_Router $1
  7663.     Do_Ifcfg default up
  7664. }
  7665.  
  7666. # Ask_HOSTNAME ( {FQ,ETHER,ROUTER,NFS_SERVER,DNS_SERVER,MAIL_SERVER}, [default] )
  7667. #
  7668. Ask_HOSTNAME()
  7669. {
  7670.   while [ 1 ]; do
  7671.     # Ask_String --prehelp ":HELP_HOSTNAME:" $1_NAME $2 || return 1
  7672.     Ask_String $1_NAME $2 || return 1
  7673.     # Fixme Check_Hostname_Valid "$ANSWER" && return 0
  7674.     return 0
  7675.   done
  7676. }
  7677.  
  7678. # Ask_IP ( [--none] [--pretext PRETEXT ] [--help HELPTEXT] [--num NO] VARNAME [default] )
  7679. #
  7680. Ask_IP()
  7681. {
  7682.   local num=
  7683.   local help=":HELP_IP:"
  7684.   local pretext=""
  7685.   local var=
  7686.   local defval=
  7687.   local none_flag=
  7688.   local ipaddr=
  7689.  
  7690.   if [ $# -gt 0 -a "$1" = '--none' ]; then
  7691.     none_flag=true
  7692.     shift 1
  7693.   fi
  7694.   if [ $# -gt 1 -a "$1" = "--pretext" ]; then
  7695.     pretext="$2"
  7696.     shift 2
  7697.   fi
  7698.   if [ $# -gt 1 -a "$1" = "--help" ]; then
  7699.     help="$2"
  7700.     shift 2
  7701.   fi
  7702.   if [ $# -gt 1 -a "$1" = "--num" ]; then
  7703.     num="$2"
  7704.     shift 2
  7705.   fi
  7706.   if [ $# -gt 0 ]; then
  7707.     if [ $# -gt 1 ]; then
  7708.       defval="$2"
  7709.     fi
  7710.     if [ -z "$defval" ]; then
  7711.       defval="`Get_Val CONF_$1${num}_IP`"
  7712.     fi
  7713.     var="$1_IP"
  7714.   fi
  7715.   if [ -z "$var" ]; then
  7716.     var="IP"
  7717.   fi
  7718.  
  7719.   while [ 1 ]; do
  7720.     Ask_String --pretext "$pretext" --help "$help" $var $defval || return 1
  7721.     if [ -z "$ANSWER" ]; then
  7722.       if [ -n "$none_flag" ]; then return 0 ; fi
  7723.     fi
  7724.     Check_IP_Addr_Valid "$ANSWER" || continue
  7725.     echo "new ANSWER = $ANSWER" >> /dev/tty4
  7726.     return 0
  7727.   done
  7728. }
  7729.  
  7730. Check_Host_Known()
  7731. {
  7732.   local f_name=Check_Host_Known
  7733.   local f_args=1 # (hostname) -> "$FILE_ETC_HOSTS entry"
  7734.  
  7735.   Check_Args $f_name $f_args $# "$@" || return 255
  7736.   sed -n "/ $1/p" $FILE_ETC_HOSTS
  7737. }
  7738.  
  7739. Check_IP_Addr_Known()
  7740. {
  7741.   local f_name=Check_IP_Addr_Known
  7742.   local f_args=1 # (ipaddr) -> "$FILE_ETC_HOSTS entry"
  7743.  
  7744.   Check_Args $f_name $f_args $# "$@" || return 255
  7745.   sed -n "/^$1/p" $FILE_ETC_HOSTS
  7746. }
  7747.  
  7748. # Verify IP address and set ANSWER to an octal clean value and
  7749. # set ANSWER2 to the corresponding netmask
  7750. #
  7751. Check_IP_Addr_Valid()
  7752. {
  7753.     local f_name=Check_IP_Addr_Valid
  7754.     local f_args=1 # (ipaddr) -> ANSWER2
  7755.     local field=
  7756.     local field1=
  7757.     local field2=
  7758.     local field3=
  7759.     local field4=
  7760.     local good=
  7761.     local octfree=
  7762.     export ANSWER2=
  7763.  
  7764.     Check_Args $f_name $f_args $# "$@" || return 255
  7765.     # Test for invalid chars
  7766.     if [ -n "`Check_Chars_Valid "$1" "0123456789\."`" ]; then
  7767.         Error ":ERR_INVALID_IP_ADDR:"
  7768.         return 1
  7769.     fi
  7770.  
  7771.     # Test for 3 dots
  7772.     if [ "`echo $1 | sed 's/[^\.]//g'`" != '...' ]; then
  7773.         Error ":ERR_INVALID_IP_ADDR:"
  7774.         return 1
  7775.     fi
  7776.  
  7777.     IFS='.' read field1 field2 field3 field4 << EOF
  7778. $1
  7779. EOF
  7780.     for field in $field1 $field2 $field3 $field4 ; do
  7781.         if [ $field -gt 255 -o 0 -gt $field ]; then
  7782.             Error ":ERR_INVALID_IP_ADDR:"
  7783.             return 1
  7784.         fi
  7785.         # make sure IP address is octal clean to make do_netcalc happy
  7786.         good="$field"
  7787.         if [ $field -gt 0 ]; then
  7788.             # cut off heading zeros
  7789.             good="`echo $field | sed 's/^[0]*//'`"
  7790.         fi
  7791.         if [ -z "$octfree" ]; then
  7792.             octfree="${good}"
  7793.         else
  7794.             octfree="${octfree}.${good}"
  7795.         fi
  7796.     done
  7797.     # overwrite ANSWER (global) with octal free value
  7798.     echo "old ANSWER = $ANSWER" >> /dev/tty4
  7799.     echo "octfree = $octfree" >> /dev/tty4
  7800.     ANSWER="$octfree"
  7801.     ANSWER2="`do_netcalc -m $ANSWER`"
  7802.     return 0
  7803. }
  7804.  
  7805. # Verify netmask for an IP addr and set ANSWER2 to corresponding broadcast
  7806. # and ANSWER3 to corresponding net
  7807. #
  7808. Check_Netmask_Valid()
  7809. {
  7810.     local f_name=Check_IP_Addr_Valid
  7811.     local f_args=2 # (netmask, ipaddr) -> ANSWER2, ANSWER3
  7812.     local i
  7813.     local field
  7814.     export ANSWER2
  7815.     export ANSWER3
  7816.  
  7817.     Check_Args $f_name $f_args $# "$@" || return 255
  7818.     Check_IP_Addr_Valid $2 || return 1 
  7819.  
  7820.     ANSWER2=
  7821.     ANSWER3=
  7822.  
  7823.     # Test for invalid chars
  7824.     if [ -n "`Check_Chars_Valid "$1" "0123456789\."`" ]; then
  7825.         Error ":ERR_INVALID_NETMASK:"
  7826.         return 1
  7827.     fi
  7828.  
  7829.     # Test for 3 dots
  7830.     if [ "`echo $1 | sed 's/[^\.]//g'`" != '...' ]; then
  7831.         Error ":ERR_INVALID_NETMASK:"
  7832.         return 1
  7833.     fi
  7834.  
  7835.     for i in 1 2 3 4 ; do
  7836.         field="`echo $1 | cut -d. -f $i`"
  7837.         if [ $field -gt 255 -o 0 -gt $field ]; then
  7838.             Error ":ERR_INVALID_NETMASK:"
  7839.             return 1
  7840.         fi
  7841.     done
  7842.     ANSWER="$1"
  7843.     ANSWER2="`do_netcalc -b $2 $1`"
  7844.     ANSWER3="`do_netcalc -n $2 $1`"
  7845.     return 0
  7846. }
  7847.  
  7848.  
  7849. Do_Setup_Mail()
  7850. {
  7851.     local fqhn=
  7852.     local shortname=
  7853.     local domainname=
  7854.  
  7855.     fqhn="`Get_Val CONF_FQ_HOSTNAME $CONF_FQ_HOSTNAME`"
  7856.     shortname="`echo $CONF_FQ_HOSTNAME | cut -d'.' -f 1`"
  7857.     domainname="`echo $CONF_FQ_HOSTNAME | cut -d'.' -f 2-`"
  7858.  
  7859.     #
  7860.     # smail konfigurieren
  7861.     #
  7862.     if [ -f $FILE_SMAIL_CONFIG.sample ]; then
  7863.         sed "{
  7864.                 s/HOSTNAME/$shortname/g
  7865.                 s/DOMAINNAME/$domainname/g
  7866.                 }" $FILE_SMAIL_CONFIG.sample > $FILE_SMAIL_CONFIG
  7867.         chmod 644 $FILE_SMAIL_CONFIG
  7868.         if [ -f /usr/lib/smail/tools.linux/mkconfig ]; then
  7869.             # Msg ":INFO_PLEASE_CONFIGURE_SMAIL:"
  7870.             ( cd /usr/lib/smail ; tools.linux/mkconfig )
  7871.         fi
  7872.     fi
  7873.  
  7874.     #
  7875.     # elm konfigurieren
  7876.     #
  7877.     if [ -f $FILE_ELM_RC.sample ]; then
  7878.         sed "{
  7879.                 s/DOMAINNAME/$domainname/g
  7880.                 s/HOSTNAME/$shortname/g
  7881.                 }" $FILE_ELM_RC.sample > $FILE_ELM_RC
  7882.         chmod 644 $FILE_ELM_RC
  7883.     fi
  7884. }
  7885.  
  7886. Do_Setup_FQ_Name()
  7887. {
  7888.   local fqhn=
  7889.   local shortname=
  7890.   local domainname=
  7891.  
  7892.   fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  7893.   shortname="`echo $fqhn | cut -d'.' -f 1`"
  7894.   domainname="`echo $fqhn | cut -d'.' -f 2-`"
  7895.   if [ -n "$shortname" ]; then
  7896.     hostname $shortname
  7897.     Do_Store CONF_NODENAME "$shortname"
  7898.     mkdir -p $DIR_TARGET/etc/sysconfig
  7899.     touch $DIR_TARGET/etc/sysconfig/network
  7900.     set_val -f $DIR_TARGET/etc/sysconfig/network HOSTNAME $fqhn
  7901.   fi
  7902.   Set_etc_HOSTNAME
  7903.   Do_Setup_DNS
  7904. }
  7905.  
  7906. Menu_Config_FQ_Name()
  7907. {
  7908.   local fqhn=
  7909.   local shortname=
  7910.   local domainname=
  7911.   local eth0name=
  7912.  
  7913.   fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  7914.   Ask_HOSTNAME FQ $fqhn || return 1
  7915.   if [ -z "$ANSWER" ]; then return 1 ; fi
  7916.   fqhn="$ANSWER"
  7917.   Do_Store CONF_FQ_HOSTNAME "$fqhn"
  7918.   Do_Setup_FQ_Name
  7919.   eth0name="`Get_Val CONF_eth0_NAME`"
  7920.   if [ -n "$eth0name" ]; then
  7921.       Do_Store CONF_eth0_NAME "$fqhn"
  7922.   fi
  7923.   Do_Setup_Hosts
  7924.   return 0
  7925. }
  7926.  
  7927.  
  7928. Do_Setup_DNS()
  7929. {
  7930.     local fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  7931.     local domainname="`echo $fqhn | cut -d'.' -f 2-`"
  7932.     local domain="`Get_Val CONF_DNS_DOMAIN`"
  7933.     local search="`Get_Val CONF_DNS_SEARCH`"
  7934.     local server1="`Get_Val CONF_DNS_SERVER1_IP`"
  7935.     local server2="`Get_Val CONF_DNS_SERVER2_IP`"
  7936.     local server3="`Get_Val CONF_DNS_SERVER3_IP`"
  7937.  
  7938.     local DomainLine=
  7939.     local SearchLine=
  7940.     local Server1Line=
  7941.     local Server2Line=
  7942.     local Server3Line=
  7943.  
  7944.     if [ -n "$domain" ]; then
  7945.         DomainLine="domain $domain"
  7946.     else
  7947.         if [ -n "$domainname" ]; then
  7948.             domain="$domainname"
  7949.             Do_Store CONF_DNS_DOMAIN "$domain"
  7950.             DomainLine="domain $domain"
  7951.         fi
  7952.     fi
  7953.     if [ -n "$search" ]; then
  7954.         SearchLine="search $search"
  7955.     else
  7956.         if [ -n "$domain" ]; then
  7957.             search="$domain"
  7958.             Do_Store CONF_DNS_SEARCH "$search"
  7959.             SearchLine="search $search"
  7960.         fi
  7961.     fi
  7962.     if [ -n "$server1" ]; then
  7963.         Server1Line="nameserver $server1"
  7964.     fi
  7965.     if [ -n "$server2" ]; then
  7966.         Server2Line="nameserver $server2"
  7967.     fi
  7968.     if [ -n "$server3" ]; then
  7969.         Server3Line="nameserver $server3"
  7970.     fi
  7971.  
  7972.     # we don't prefix it with $DIR_TARGET as we copy it later
  7973.  
  7974.     cat << EOF > $FILE_ETC_RESOLV_CONF
  7975. # $FILE_ETC_RESOLV_CONF - DNS setup file
  7976. #
  7977. # possible entries are:
  7978. #
  7979. #    domain <domain>            Local domain name. If not present, the
  7980. #                    gethostbyname syscall is used to
  7981. #                    determine the local domain name.
  7982. #
  7983. #    search <list_of_domains>    Search list for hostname lookup.
  7984. #                    The search list is normally determined
  7985. #                    from the local domain name but it
  7986. #                    can be set to a list of domains.
  7987. #
  7988. #    nameserver <ip_addr>        Define which server to contact
  7989. #                                       for DNS lookups. If there are
  7990. #                    multiple nameserver lines (Max=3),
  7991. #                    they are queried in the listed order.
  7992. #
  7993. # !!! Automatically generated by LISA from /etc/system.cnf. Do not edit !!!
  7994. #
  7995. $DomainLine
  7996. $SearchLine
  7997. $Server1Line
  7998. $Server2Line
  7999. $Server3Line
  8000. EOF
  8001.     chmod 644 $FILE_ETC_RESOLV_CONF
  8002. }
  8003.  
  8004. Menu_Config_DNS()
  8005. {
  8006.     local server1="`Get_Val CONF_DNS_SERVER1_IP`"
  8007.     local server2="`Get_Val CONF_DNS_SERVER2_IP`"
  8008.     local server3="`Get_Val CONF_DNS_SERVER3_IP`"
  8009.     local dnssetup=NONE
  8010.  
  8011.     local num
  8012.     local retry
  8013.     local none_flag
  8014.  
  8015.     while [ 1 ]; do
  8016.         retry=
  8017.         none_flag=
  8018.         Ask_Bool DNS_SERVER || return 1
  8019.         if [ "$ANSWER" = "0" ]; then
  8020.             dnssetup=CLIENT
  8021.         else
  8022.             dnssetup=SERVER
  8023.         fi
  8024.  
  8025.         case $dnssetup in
  8026.         SERVER)
  8027.             # Ask_Bool DNS_SERVER_LOCAL n || return 1
  8028.             ANSWER=1
  8029.             case $ANSWER in
  8030.             0)
  8031.                 # setup localhost as nameserver
  8032.                 server1="127.0.0.1"
  8033.                 server2=
  8034.                 server3=
  8035.                 Err_Not_Implemented
  8036.                 ;;
  8037.             1)
  8038.                 # then we just use $FILE_ETC_HOSTS
  8039.                 server1=
  8040.                 server2=
  8041.                 server3=
  8042.                 ;;
  8043.             esac
  8044.             ;;
  8045.         CLIENT)
  8046.             # We are a DNS client. Ask for IP addr of DNS servers.
  8047.             for num in 1 2 3 ; do
  8048.                 if [ $num -gt 1 ]; then none_flag='--none' ; fi
  8049.                 none_flag='--none'
  8050.                 Ask_IP $none_flag --pretext "DNS server $num ; " --help ":HELP_IP:" --num $num DNS_SERVER
  8051.                 if [ $? -ne 0 ]; then retry=true ; break ; fi
  8052.                 if [ -z "$ANSWER" ]; then break ; fi
  8053.                 eval "`echo \"server$num=$ANSWER\"`"
  8054.             done
  8055.             ;;
  8056.         esac
  8057.         if [ -n "$retry" ]; then continue ; fi
  8058.         break
  8059.     done
  8060.     Do_Store CONF_DNS_SERVER1_IP "$server1"
  8061.     Do_Store CONF_DNS_SERVER2_IP "$server2"
  8062.     Do_Store CONF_DNS_SERVER3_IP "$server3"
  8063.     Do_Setup_DNS
  8064. }
  8065.  
  8066. Menu_Config_Netdev()
  8067. {
  8068.     export ANSWER=
  8069.     local supported_netdevs="eth0 eth1 tr0 plip0 plip1 plip2"
  8070.     local dev=
  8071.     local ip=
  8072.     local remote_ip=
  8073.     local mask=
  8074.     local bcast=
  8075.     local net=
  8076.     local name=
  8077.     local trydev=
  8078.  
  8079.     # FIXME: supports all network devices, not only a limited list
  8080.     for trydev in $supported_netdevs ; do
  8081.         if [ -n "`fgrep $trydev /proc/net/dev`" ]; then
  8082.             dev="$trydev"
  8083.             break
  8084.         fi
  8085.     done
  8086.  
  8087.     # FIXME: A list of available devices should be created dynamically
  8088.     Ask_String ETHER_DEV $dev || return 1
  8089.     dev="$ANSWER"
  8090.     if [ -z "`fgrep $dev /proc/net/dev`" ]; then
  8091.         Error "$dev ; :ERR_NO_DEVICE_AND_NO_MODULE:"
  8092.         # FIXME: this should fall back to module loading...
  8093.         return 1
  8094.     fi
  8095.  
  8096.     case $dev in
  8097.     lo|eth0|eth1|plip0|plip1|plip2|tr0)
  8098.         ;;
  8099.     *)
  8100.         Err_Not_Implemented
  8101.         return 1
  8102.         ;;
  8103.     esac
  8104.  
  8105.     while [ 1 ]; do
  8106.         # interface device
  8107.         Do_Store CONF_${dev}_DEV "$dev"
  8108.  
  8109.         # interface ip
  8110.         ip="`Get_Val CONF_${dev}_IP`"
  8111.         if [ -z "$ip" ]; then
  8112.             ip=192.168.0.1
  8113.         fi
  8114.         Ask_IP ETHER $ip || continue
  8115.         ip="$ANSWER"
  8116.         Do_Store CONF_${dev}_IP "$ip"
  8117.  
  8118.         if [ "$dev" = "plip0" -o "$dev" = "plip1" ]; then
  8119.             # remote (pointopoint) ip
  8120.             remote_ip="`Get_Val CONF_${dev}_REMOTE_IP`"
  8121.             if [ -z "$remote_ip" ]; then
  8122.                 remote_ip=192.168.0.2
  8123.             fi
  8124.             Ask_IP ETHER_REMOTE $remote_ip || continue
  8125.             remote_ip="$ANSWER"
  8126.             Do_Store CONF_${dev}_REMOTE_IP "$remote_ip"
  8127.         else
  8128.             # interface netmask, broadcast and netroute
  8129.             if [ -z "$ANSWER2" ]; then
  8130.                 ANSWER2="255.255.255.0"
  8131.             fi
  8132.  
  8133.             mask="`Get_Val CONF_${dev}_MASK`"
  8134.             if [ -z "$mask" ]; then
  8135.                 mask="$ANSWER2"
  8136.             fi
  8137.             Ask_String NETMASK $mask || continue
  8138.             mask="$ANSWER"
  8139.             Check_Netmask_Valid "$mask" $ip || continue
  8140.             bcast="$ANSWER2"
  8141.             net="$ANSWER3"
  8142.  
  8143.             Ask_String BROADCAST $bcast || continue
  8144.             bcast="$ANSWER"
  8145.  
  8146.             Do_Store CONF_${dev}_MASK "$mask"
  8147.             Do_Store CONF_${dev}_BCAST "$bcast"
  8148.             Do_Store CONF_${dev}_NET "$net"
  8149.         fi
  8150.         break
  8151.     done
  8152.  
  8153.     # assumption: interface name = hostname
  8154.     name="`Get_Val CONF_FQ_HOSTNAME`"
  8155.     Do_Store CONF_${dev}_NAME "$name"
  8156.     Do_Setup_Hosts
  8157.     Set_network
  8158.     Do_Ifcfg $dev up > $FILE_TMP_ERR 2>&1
  8159.     Do_Store CONF_${dev}_STAT up
  8160.     Set_ifcfg ${dev}
  8161.     ANSWER="${dev}"
  8162.     return 0
  8163. }
  8164.  
  8165. Menu_Config_Ether()
  8166. {
  8167.     export ANSWER=
  8168.     local first_install=
  8169.     local shortname=
  8170.     local fqhn=
  8171.     local dev=eth0
  8172.     local ip=
  8173.     local pointopoint=
  8174.     local mask=
  8175.     local bcast=
  8176.     local net=
  8177.     local name=
  8178.  
  8179.     if [ $# -gt 0 -a "$1" = "first" ]; then
  8180.         first_install=true
  8181.         shift 1
  8182.     fi
  8183.  
  8184.     if [ $# -gt 0 -a "$1" = "eth1" ]; then
  8185.         dev=eth1
  8186.         shift 1
  8187.     fi
  8188.  
  8189.     while [ 1 ]; do
  8190.         if [ -n "$first_install" ]; then
  8191.             Do_Store CONF_${dev}_STAT up
  8192.         else
  8193.             Ask_Bool ETHER || return 1
  8194.             case $ANSWER in 
  8195.             0)
  8196.                 Do_Store CONF_${dev}_STAT up
  8197.                 prep_use NETCONF
  8198.                 ;;
  8199.             1)
  8200.                 Do_Store CONF_${dev}_STAT down
  8201.                 return 0
  8202.                 ;;
  8203.             esac
  8204.         fi
  8205.  
  8206.         # interface device
  8207.         Debug "Calling Get_Val"
  8208.         dev="`Get_Val CONF_${dev}_DEV`"
  8209.         if [ -z "$dev" ]; then
  8210.             dev="eth0"
  8211.         fi
  8212.         Ask_String ETHER_DEV $dev || return 1
  8213.         dev="$ANSWER"
  8214.         if [ -z "`fgrep $dev /proc/net/dev`" ]; then
  8215.             Error "$dev ; :ERR_NO_DEVICE_AND_NO_MODULE:"
  8216.             # FIXME: this should fall back to module loading...
  8217.             return 1
  8218.         fi
  8219.         Do_Store CONF_${dev}_DEV "$dev"
  8220.  
  8221.         # interface ip
  8222.         ip="`Get_Val CONF_${dev}_IP`"
  8223.         Ask_IP ETHER $ip || continue
  8224.         ip="$ANSWER"
  8225.         Do_Store CONF_${dev}_IP "$ip"
  8226.  
  8227.         # interface netmask, broadcast and netroute
  8228.         if [ -z "$ANSWER2" ]; then
  8229.             ANSWER2="255.255.255.0"
  8230.         fi
  8231.  
  8232.         mask="`Get_Val CONF_${dev}_MASK`"
  8233.         if [ -z "$mask" ]; then
  8234.             mask="$ANSWER2"
  8235.         fi
  8236.         Ask_String NETMASK $mask || continue
  8237.         Check_Netmask_Valid "$ANSWER" $ip || continue
  8238.         mask="$ANSWER"
  8239.         bcast="$ANSWER2"
  8240.         net="$ANSWER3"
  8241.  
  8242.         Ask_String BROADCAST $bcast || continue
  8243.         bcast="$ANSWER"
  8244.  
  8245.         Do_Store CONF_${dev}_MASK "$mask"
  8246.         Do_Store CONF_${dev}_BCAST "$bcast"
  8247.         Do_Store CONF_${dev}_NET "$net"
  8248.         break
  8249.     done
  8250.  
  8251.     # assumption: interface name = hostname
  8252.     fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  8253.     name="$fqhn"
  8254.     Do_Store CONF_${dev}_NAME "$name"
  8255.     Do_Setup_Hosts
  8256.     Set_network
  8257.     Do_Ifcfg $dev up > $FILE_TMP_ERR 2>&1
  8258.     Set_ifcfg ${dev}
  8259.     return 0
  8260. }
  8261.  
  8262. Do_Setup_Hosts()
  8263. {
  8264.     local fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  8265.     local nodename="`echo $fqhn | cut -d'.' -f 1`"
  8266.     local eth0name="`Get_Val CONF_eth0_NAME`"
  8267.     local eth1name="`Get_Val CONF_eth1_NAME`"
  8268.     local tr0name="`Get_Val CONF_tr0_NAME`"
  8269.  
  8270.     local LocalhostLine=
  8271.     local eth0Line=
  8272.     local eth1Line=
  8273.     local tr0Line=
  8274.     local shortname=
  8275.  
  8276.     if [ -n "$eth0name" ]; then
  8277.         shortname="`echo $eth0name | cut -d'.' -f 1`"
  8278.         eth0Line="`Get_Val CONF_eth0_IP` $eth0name $shortname"
  8279.     fi
  8280.     if [ -n "$eth1name" ]; then
  8281.         shortname="`echo $eth1name | cut -d'.' -f 1`"
  8282.         eth1Line="`Get_Val CONF_eth1_IP` $eth1name $shortname"
  8283.     fi
  8284.     if [ -n "$tr0name" ]; then
  8285.         shortname="`echo $tr0name | cut -d'.' -f 1`"
  8286.         tr0Line="`Get_Val CONF_tr0_IP` $tr0name $shortname"
  8287.     fi
  8288.     if [ "$fqhn" != "$nodename" ]; then
  8289.         shortname="$nodename"
  8290.     fi
  8291.     if [ -z "${eth0name}${eth1name}${tr0name}" ]; then
  8292.         LocalhostLine="127.0.0.1 $fqhn $shortname localhost"
  8293.     else
  8294.         LocalhostLine="127.0.0.1 localhost"
  8295.     fi
  8296.  
  8297.     # we don't prefix it with $DIR_TARGET as we copy it later
  8298.  
  8299.     Do_Backup_File $FILE_ETC_HOSTS
  8300.  
  8301.     cat << EOF > $FILE_ETC_HOSTS
  8302. # $FILE_ETC_HOSTS -  hostname_to_address mappings for the resolver library
  8303. #
  8304. # The format is:
  8305. #
  8306. # ipaddr fully_qualified_hostname list_of_nicknames
  8307. #
  8308. # We strongly recommend to use a fully qualified hostname for your machine
  8309. # if it is connected to any type of network. You can add short nicknames as
  8310. # you like, but the official canonical name is the name that follows the
  8311. # IP address and should always be a fully qualified hostname.
  8312. #
  8313. # If you don't have any network interfaces, you should put your hostname
  8314. # in the line of your loopback device, which has the address 127.0.0.1.
  8315. #
  8316. # LISA will automatically put the hostname in the right line for you.
  8317. #
  8318. #
  8319. # !!! Automatically generated by LISA from /etc/system.cnf. Do not edit !!!
  8320. #
  8321. # The loopback device. It should always be available.
  8322. #
  8323. $LocalhostLine
  8324. #
  8325. # Your first IP interface (if you are connected to any kind of network)
  8326. #
  8327. $eth0Line
  8328. $tr0Line
  8329. #
  8330. # Your second IP interface (normally for routers only)
  8331. #
  8332. $eth1Line
  8333. #
  8334. # If you have a nameserver we recommend to use it instead of putting many
  8335. # hosts in this file. If you don't have a nameserver though, you can add
  8336. # hostnames and their IP addresses below this line.
  8337. #
  8338. #===========================================================================
  8339. EOF
  8340.     chmod 644 $FILE_ETC_HOSTS
  8341.     if [ -f ${FILE_ETC_HOSTS}~ ]; then
  8342.         sed -n '/^#====/,${
  8343.             /^#====/d
  8344.             p
  8345.         }' ${FILE_ETC_HOSTS}~ >> $FILE_ETC_HOSTS
  8346.     fi
  8347. }
  8348.  
  8349.  
  8350.  
  8351. Do_Setup_NIS_glibc()
  8352. {
  8353.     local domain="`Get_Val CONF_NIS_DOMAIN`"
  8354.     local server1="`Get_Val CONF_NIS_SERVER1_IP`"
  8355.     local server2="`Get_Val CONF_NIS_SERVER2_IP`"
  8356.     local server3="`Get_Val CONF_NIS_SERVER3_IP`"
  8357.  
  8358.     local DomainLine=
  8359.     local Server1Line=
  8360.     local Server2Line=
  8361.     local Server3Line=
  8362.  
  8363.     if [ -n "$domain" ]; then
  8364.         DomainLine="domain $domain"
  8365.         domainname $domain
  8366.     fi
  8367.     if [ -n "$server1" ]; then
  8368.         Server1Line="$DomainLine server $server1"
  8369.     else
  8370.         Server1Line="$DomainLine broadcast"
  8371.     fi
  8372.     if [ -n "$server2" ]; then
  8373.         Server2Line="ypserver $server2"
  8374.     fi
  8375.     if [ -n "$server3" ]; then
  8376.         Server3Line="ypserver $server3"
  8377.     fi
  8378.  
  8379.     cat << EOF > $DIR_TARGET$FILE_NIS_CONF
  8380. # $FILE_NIS_CONF - NIS setup file
  8381. #
  8382. # possible entries are:
  8383. #
  8384. #    domain <domain> broadcast    This is the default NIS domain;
  8385. #                    Broadcasts are used to find an
  8386. #                    eligible server (insecure).
  8387. #        alternatively
  8388. #
  8389. #    domain <domain> server <ip>    Additionally specify which host
  8390. #                    to contact for NIS service.
  8391. #
  8392. #    ypserver <ip>            Fall-Back servers for NIS can
  8393. #                    be added this way for the case
  8394. #                    that the primary server is down.
  8395. #
  8396. # !!! This file may be automatically regenerated by LISA from
  8397. # /etc/system.cnf. Edit at your own risk !!!
  8398. #
  8399. $Server1Line
  8400. $Server2Line
  8401. $Server3Line
  8402. EOF
  8403.     chmod 644 $DIR_TARGET$FILE_NIS_CONF
  8404.     # filter out NIS lines from passwd and group
  8405.     sed '/^\+/d' $DIR_TARGET$FILE_ETC_PASSWD > $DIR_TARGET$FILE_ETC_PASSWD.tmp
  8406.     sed '/^\+/d' $DIR_TARGET$FILE_ETC_GROUP > $DIR_TARGET$FILE_ETC_GROUP.tmp
  8407.     if [ -n "$domain" ]; then
  8408.         # add NIS lines to passwd and group if NIS domain set
  8409.         echo "+::::::"     >> $DIR_TARGET$FILE_ETC_PASSWD.tmp
  8410.         echo "+:::"     >> $DIR_TARGET$FILE_ETC_GROUP.tmp
  8411.     fi
  8412.     chmod 644 $DIR_TARGET$FILE_ETC_PASSWD.tmp
  8413.     chmod 644 $DIR_TARGET$FILE_ETC_GROUP.tmp
  8414.     mv $DIR_TARGET$FILE_ETC_PASSWD.tmp $DIR_TARGET$FILE_ETC_PASSWD
  8415.     mv $DIR_TARGET$FILE_ETC_GROUP.tmp $DIR_TARGET$FILE_ETC_GROUP
  8416. }
  8417.  
  8418. Menu_Config_NIS()
  8419. {
  8420.     local dir_daemons=$DIR_TARGET/etc/sysconfig/daemons
  8421.     local num
  8422.     local retry
  8423.     local none_flag
  8424.     local nisdomain="`Get_Val CONF_NIS_DOMAIN`"
  8425.     local server1="`Get_Val CONF_NIS_SERVER1_IP`"
  8426.     local server2="`Get_Val CONF_NIS_SERVER2_IP`"
  8427.     local server3="`Get_Val CONF_NIS_SERVER3_IP`"
  8428.     local nissetup
  8429.  
  8430.     # try to find a good default value
  8431.     if [ -n "$nisdomain" ]; then
  8432.         if [ -n "$server1$server2$server3" ]; then
  8433.             nissetup=CLIENT
  8434.         else
  8435.             nissetup=SERVER
  8436.         fi
  8437.     else
  8438.         nissetup=NONE
  8439.     fi
  8440.  
  8441.     while [ 1 ]; do
  8442.         retry=
  8443.         none_flag=
  8444.         Choose --none NIS $nissetup || return 1
  8445.         nissetup="$ANSWER"
  8446.         if [ -z "$nissetup" ]; then
  8447.             nisdomain=
  8448.             server1=
  8449.             server2=
  8450.             server3=
  8451.             # disable nis server autostart
  8452.             Do_Setup_Daemon nis-server no
  8453.             break
  8454.         fi
  8455.         Ask_String NIS_DOMAIN $nisdomain || continue
  8456.         nisdomain="$ANSWER"
  8457.  
  8458.         case $nissetup in
  8459.         SERVER)
  8460.             # we are NIS server and client.
  8461.             server1=127.0.0.1
  8462.             # enable nis server autostart
  8463.             Do_Setup_Daemon nis-server yes
  8464.             ;;
  8465.         CLIENT)
  8466.             # We are a NIS client. Ask for IP addr of NIS servers.
  8467.             for num in 1 2 3 ; do
  8468.                 if [ $num -gt 1 ]; then none_flag='--none' ; fi
  8469.                 none_flag='--none'
  8470.                 Ask_IP $none_flag --pretext "NIS server $num ; " --help ":HELP_NIS_SERVER: :HELP_IP:" --num $num NIS_SERVER
  8471.                 if [ $? -ne 0 ]; then retry=true ; break ; fi
  8472.                 if [ -z "$ANSWER" ]; then break ; fi
  8473.                 eval "`echo \"server$num=$ANSWER\"`"
  8474.             done
  8475.             # disable nis server autostart
  8476.             Do_Setup_Daemon nis-server no
  8477.             if [ -f $dir_daemons/nis-client ]; then
  8478.                 Do_Setup_Daemon nis-client yes
  8479.             fi
  8480.             ;;
  8481.         esac
  8482.         if [ -n "$retry" ]; then continue ; fi
  8483.         break
  8484.     done
  8485.     Do_Store CONF_NIS_DOMAIN "$nisdomain"
  8486.     Do_Store CONF_NIS_SERVER1_IP "$server1"
  8487.     Do_Store CONF_NIS_SERVER2_IP "$server2"
  8488.     Do_Store CONF_NIS_SERVER3_IP "$server3"
  8489.     Do_Setup_NIS_glibc
  8490.     return 0
  8491. }
  8492.  
  8493. Menu_Config_Router()
  8494. {
  8495.     local first_install=
  8496.     local defval=
  8497.     local v=CONF_ROUTER1_IP
  8498.     local r_ip="`Get_Val $v`"
  8499.     local my_net="`Get_Val CONF_eth0_NET`"
  8500.     local prefix=
  8501.     local suffix=
  8502.  
  8503.     if [ $# -gt 0 -a "$1" = "first" ]; then
  8504.         first_install=true
  8505.         shift 1
  8506.     fi
  8507.  
  8508.     if [ -n "$r_ip" -o -n "$first_install" ]; then
  8509.         defval=j
  8510.     else
  8511.         defval=n
  8512.     fi
  8513.  
  8514.     Ask_Bool ROUTER $defval
  8515.     if [ "$ANSWER" = "1" ]; then
  8516.         Do_Store $v ""
  8517.         return 0
  8518.     fi
  8519.  
  8520.     if [ -z "$r_ip" ]; then
  8521.         # try to make a good suggestion for the Router IP
  8522.         if [ -n "$my_net" ]; then
  8523.             prefix="`echo $my_net | cut -d'.' -f 1-3`"
  8524.             suffix="`echo $my_net | cut -d'.' -f 4`"
  8525.             suffix="`do_calc $suffix + 1`"
  8526.             r_ip="${prefix}.${suffix}"
  8527.         fi
  8528.     fi
  8529.  
  8530.     Ask_IP ROUTER $r_ip || return 1
  8531.     r_ip="$ANSWER"
  8532.  
  8533.     Do_Store $v "$r_ip"
  8534.     Set_ifcfg eth0
  8535.     if [ -n "$r_ip" ]; then
  8536.         Do_Ifcfg default up
  8537.     fi
  8538.     return 0
  8539. }
  8540.  
  8541. Ask_HOST()
  8542. {
  8543.     local num=
  8544.     if [ $# -gt 1 -a "$1" = "--num" ]; then
  8545.         num="--num $2"
  8546.         shift 2
  8547.     fi
  8548.     Ask_IP $num $1 || return 1
  8549.     return 0
  8550. }
  8551.  
  8552.  
  8553.  
  8554.  
  8555. Prepare_SMB_Install()
  8556. {
  8557.     Info "Switching to SMB install mode (BETA)"
  8558.     sleep 5
  8559.     MountModulesFloppy || return 1
  8560.     while [ 1 ]; do
  8561.         Do_Load_Module_mini --silent smbfs "" || break
  8562.         if [ ! -f /floppy/usr/bin/smbmount.gz ]; then break ; fi
  8563.         cp -a /floppy/usr/bin/smbmount.gz /usr/bin || break
  8564.         gunzip /usr/bin/smbmount.gz || break
  8565.         return 0
  8566.     done
  8567.     umount /floppy
  8568.     Msg "Problems with smbfs or smbmount. SMB install not possible."
  8569.     return 1
  8570. }
  8571.  
  8572. Menu_Mount_NFS()
  8573. {
  8574.   local nfsserver="$1"
  8575.   local mountdir="$2"
  8576.   local nfspath="$3"
  8577.   local smbuser="Administrator"
  8578.   local netbiosname=""
  8579.  
  8580.   export ANSWER=
  8581.   while [ 1 ]; do
  8582.     Ask_String INSTALL_PATH_SRC $nfspath || return 1
  8583.     nfspath="$ANSWER"
  8584.     if [ -z "$mountdir" ]; then
  8585.       Ask_String MOUNT_TARGET_DIR || continue 
  8586.     fi
  8587.     if [ "`echo $nfspath | cut -c1,2`" = '//' ]; then
  8588.     # Dirty hack to support SMB installs
  8589.     Prepare_SMB_Install
  8590.     netbiosname="`echo $nfspath | cut -d'/' -f 3`"
  8591.     $CMD_BOX --string "SMB login name" --default "$smbuser" 2> $FILE_TMP_ANSWER || continue
  8592.     smbuser="`cat $FILE_TMP_ANSWER`"
  8593.     echo "$nfsserver $netbiosname" >> /etc/hosts
  8594.     if [ -n "$smbuser" ]; then
  8595.         reset 2>&1
  8596.         Do_Clear_Screen
  8597.         echo "smbmount $nfspath /mnt -I $nfsserver -U $smbuser"
  8598.         smbmount $nfspath /mnt -I $nfsserver -U $smbuser 2>&1
  8599.         if [ $? -eq 0 ]; then break ; fi
  8600.     else
  8601.         smbmount $nfspath /mnt -I $nfsserver -n && break
  8602.     fi
  8603.     echo -n "smbmount failed. press <return> to continue."
  8604.     read ans
  8605.     # cleanup /etc/hosts if the mount failed
  8606.     sed "/^${nfsserver} ${netbiosname}$/d" /etc/hosts > /etc/hosts.tmp
  8607.     mv /etc/hosts.tmp /etc/hosts
  8608.     else
  8609.         Do_Mount -o ro "${nfsserver}:${nfspath}" $mountdir && break
  8610.     fi
  8611.   done
  8612.   export ANSWER="${nfspath}"
  8613.   return 0
  8614. }
  8615.  
  8616.  
  8617. # libLSTpkg - package handling library shared between several scripts
  8618. #
  8619. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  8620. #
  8621.  
  8622. Build_SERIES()
  8623. {
  8624.   Do_Calc_Freespace $DIR_TARGET
  8625.  
  8626.   touch $FILE_PKGS_SEL
  8627.   build_menu -U $FREESPACE -f -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA
  8628. }
  8629.  
  8630. Get_Dependend_Pkgs()
  8631. {
  8632.   local preset=$1
  8633.  
  8634.   Debug "add dependend pkgs for $preset"
  8635.  
  8636.   # add pcmcia where necessary
  8637.   case $preset in
  8638.   min|minx|small)
  8639.     if [ -n "`sed -n '/^pcmcia_core/p' /proc/modules`" ]; then
  8640.       echo "pcmcia-cs"
  8641.     fi
  8642.     ;;
  8643.   esac
  8644. }
  8645.  
  8646. Get_Preset_Pkgs()
  8647. {
  8648.   local preset=$1
  8649.   local preset_file=/floppy/usr/lib/LST/pkgs.$preset.gz
  8650.   local series
  8651.  
  8652.   Debug "generate preset pkgs for $preset"
  8653.  
  8654.   if [ "$CND10_MODE" = "true" ]; then
  8655.     # use fixed preset file
  8656.     if [ -r $preset_file ]; then
  8657.       gzip -dfcv < $preset_file | sed '/^#/d'
  8658.     else
  8659.       Debug "preset file $preset not found. Use all."
  8660.       build_menu -n -p ":1:" -d $FILE_PKGS_DATA
  8661.     fi
  8662.   else
  8663.     case $preset in
  8664.     min)
  8665.       # only default packages of series basis and network
  8666.       for series in basis network ; do
  8667.     build_menu -n -c 1 -s $series -m ":2:j:" -p ":1:" -d $FILE_PKGS_DATA
  8668.       done
  8669.       ;;
  8670.     minx)
  8671.       # only default packages of series basis, network, xbasis and xappl
  8672.       for series in basis network xbasis xappl ; do
  8673.     build_menu -n -c 1 -s $series -m ":2:j:" -p ":1:" -d $FILE_PKGS_DATA
  8674.       done
  8675.       ;;
  8676.     small)
  8677.       # only default of all series
  8678.       for series in basis develop doku network tex text xappl xbasis xdevelo xemacs xextra xview ; do
  8679.     build_menu -n -c 1 -s $series -m ":2:j:" -p ":1:" -d $FILE_PKGS_DATA
  8680.       done
  8681.       ;;
  8682.     rec)
  8683.       # all pkgs of series basis
  8684.       for series in basis ; do
  8685.     build_menu -n -s $series -p ":1:" -d $FILE_PKGS_DATA
  8686.       done
  8687.  
  8688.       # all pkgs of series xbasis but no X servers
  8689.       sed '/^XSERV:/d' $FILE_PKGS_DATA | build_menu -n -s xbasis -p ":1:"
  8690.  
  8691.       # rec pkgs of series text,doku,develop,misc,network,tex,xappl,xemacs,xview
  8692.       for series in develop doku misc network text tex xappl xemacs xview ; do
  8693.     build_menu -n -c 2 -s $series -m ":2:j:" -p ":1:" -d $FILE_PKGS_DATA
  8694.       done
  8695.       ;;
  8696.     all)
  8697.       # all pkgs
  8698.       build_menu -n -p ":1:" -d $FILE_PKGS_DATA
  8699.       ;;
  8700.     sel)
  8701.       # expert's private choice ;-)
  8702.       build_menu -t /usr/lib/LST/pkgs.sel -n -p ":1:" -d $FILE_PKGS_DATA
  8703.       ;;
  8704.     esac
  8705.     Get_Dependend_Pkgs $preset
  8706.   fi
  8707. }
  8708.  
  8709. Get_Preset_Size()
  8710. {
  8711.   local preset=$1
  8712.   # we have an overhead of about 20% for inodes, administrative data etc.
  8713.   # current algorithm is (x MB + 2 MB) * 1.20
  8714.   local fudge_factor=20
  8715.   local approx_usage=
  8716.   local preset_file=/floppy/usr/lib/LST/pkgs.$preset.gz
  8717.  
  8718.   if [ "$CND10_MODE" = "true" ]; then
  8719.     if [ -r $preset_file ]; then
  8720.       # grep precalculated from preset file
  8721.       gzip -dfcv < $preset_file |
  8722.         sed -n 's/^#% NEEDSPACE: ([0-9][0-9]*) MB.*/\1/p'
  8723.     else
  8724.       echo "?"
  8725.     fi
  8726.   else
  8727.     # generate selection list depending on the preset type
  8728.     Get_Preset_Pkgs $preset > $FILE_PKGS_SEL
  8729.     Do_Calc_Needspace $FILE_PKGS_SEL
  8730.     approx_usage="`do_calc $NEEDSPACE \* $fudge_factor`"
  8731.     approx_usage="`do_calc $approx_usage / 100`"
  8732.     approx_usage="`do_calc $approx_usage \+ $NEEDSPACE`"
  8733.     do_calc $approx_usage / 1048576
  8734.   fi
  8735. }
  8736.  
  8737. Build_PKG_SELECT()
  8738. {
  8739.   local Size_REC=
  8740.   local Size_MIN=
  8741.   local Size_MINX=
  8742.   local Size_SMALL=
  8743.   local Size_ALL=
  8744.   local Size_SEL=
  8745.   local Size_SPARE=
  8746.  
  8747.   if [ -f /usr/lib/LST/pkgs.sel ]; then
  8748.     Size_SEL="`Get_Preset_Size sel`"
  8749.     cat << EOF
  8750. "Menu_Pkg_Select_Preset sel" ":MENU_PKG_SELECT_PRESET_SEL: (min. $Size_SEL MB)" \\
  8751. EOF
  8752.   fi
  8753.   if [ "$DIR_TARGET" = "/" ]; then
  8754.     cat << EOF
  8755. "Menu_Pkg_Select_Pkgs" ":MENU_PKG_SELECT_PKGS:" \\
  8756. "Menu_Pkg_Select_Series" ":MENU_PKG_SELECT_SERIES:" \\
  8757. EOF
  8758.   else
  8759.     Size_REC="`Get_Preset_Size rec`"
  8760.     Size_MIN="`Get_Preset_Size min`"
  8761.     Size_MINX="`Get_Preset_Size minx`"
  8762.     Size_SMALL="`Get_Preset_Size small`"
  8763.     Size_ALL="`Get_Preset_Size all`"
  8764.     # SPARESPACE is in Bytes; we need MB
  8765.     Size_SPARE="`do_calc $SPARESPACE / 1048576`"
  8766.     Size_REC="`do_calc $Size_REC + $Size_SPARE`"
  8767.     Size_MIN="`do_calc $Size_MIN + $Size_SPARE`"
  8768.     Size_MINX="`do_calc $Size_MINX + $Size_SPARE`"
  8769.     Size_SMALL="`do_calc $Size_SMALL + $Size_SPARE`"
  8770.     Size_ALL="`do_calc $Size_ALL + $Size_SPARE`"
  8771.     cat << EOF
  8772. "Menu_Pkg_Select_Preset min" ":MENU_PKG_SELECT_PRESET_MIN: (min. $Size_MIN MB)" \\
  8773. EOF
  8774.     if [ "$CND10_MODE" != "true" ]; then
  8775.       cat << EOF
  8776. "Menu_Pkg_Select_Preset minx" ":MENU_PKG_SELECT_PRESET_MINX: (min. $Size_MINX MB)" \\
  8777. "Menu_Pkg_Select_Preset small" ":MENU_PKG_SELECT_PRESET_SMALL: (min. $Size_SMALL MB)" \\
  8778. EOF
  8779.     fi
  8780.     cat << EOF
  8781. "Menu_Pkg_Select_Preset rec" ":MENU_PKG_SELECT_PRESET_REC: (min. $Size_REC MB)" \\
  8782. "Menu_Pkg_Select_Preset all" ":MENU_PKG_SELECT_PRESET_ALL: (min. $Size_ALL MB)" \\
  8783. EOF
  8784.     if [ "$CND10_MODE" != "true" ]; then
  8785.       cat << EOF
  8786. "Menu_Pkg_Select_Services" ":MENU_PKG_SELECT_SERVICES:" \\
  8787. "Menu_Pkg_Select_Series" ":MENU_PKG_SELECT_SERIES:" \\
  8788. EOF
  8789.     fi
  8790.     # offer customizable selection in expert mode
  8791.     Is_Expert
  8792.     if [ $? -eq 0 ]; then
  8793.       cat << EOF
  8794. "Menu_Pkg_Select_Pkgs" ":MENU_PKG_SELECT_PKGS:" \\
  8795. EOF
  8796.     fi
  8797.   fi
  8798. }
  8799.  
  8800. Build_SELECT_PRIO()
  8801. {
  8802.   local statistics=
  8803.   local dummy=
  8804.   local pkgnum=
  8805.   local summin=
  8806.   local sumrec=
  8807.   local sumall=
  8808.   local sumsel=
  8809.  
  8810.   # Get statistics
  8811.   touch $FILE_PKGS_SEL
  8812.   touch $DIR_LST_TMP/$1.sel
  8813.   statistics="`build_menu -S -s $1 -T $DIR_LST_TMP/$1.sel -d $FILE_PKGS_DATA`"
  8814.  
  8815.   Debug "statistics for SERIES <$1> is <$statistics>"
  8816.  
  8817.   if [ -z "$statistics" ]; then
  8818.     cat << EOF
  8819. "1" ":TYPE_SEL_MIN:" \\
  8820. "2" ":TYPE_SEL_REC:" \\
  8821. "3" ":TYPE_SEL_ALL:" \\
  8822. "0" ":TYPE_SEL_NOT:" \\
  8823. EOF
  8824.   else
  8825.     IFS=':' read dummy dummy pkgnum summin sumrec sumall sumsel dummy << EOF
  8826. $statistics
  8827. EOF
  8828.     cat << EOF
  8829. --menutitle ":CHOOSE_SELECT_PRIO_MENUTITLE: $1 ($pkgnum :PKGS:)" \\
  8830. EOF
  8831.     if [ -s $DIR_LST_TMP/$SERIES.sel -a "$sumsel" != "0" ]; then
  8832.       echo "\"4\" \":TYPE_SEL_LAST:\" \\"
  8833.     fi
  8834.     cat << EOF
  8835. "1" ":TYPE_SEL_MIN: ($summin kB)" \\
  8836. "2" ":TYPE_SEL_REC: ($sumrec kB)" \\
  8837. "3" ":TYPE_SEL_ALL: ($sumall kB)" \\
  8838. EOF
  8839.     echo "\"0\" \":TYPE_SEL_NOT:\" \\"
  8840.   fi
  8841. }
  8842.  
  8843. Build_INSTALL_MEDIUM()
  8844. {
  8845.   # "tape" ":TYPE_INSTALL_MEDIUM_TAPE:"
  8846.   # "slip" ":TYPE_INSTALL_MEDIUM_SLIP:" 
  8847.   if [ "$DIR_TARGET" = "/" ]; then
  8848.     cat << EOF
  8849. "path" ":TYPE_INSTALL_MEDIUM_PATH:" \\
  8850. EOF
  8851.   fi
  8852.   cat << EOF
  8853. "cdrom" ":TYPE_INSTALL_MEDIUM_CDROM:" \\
  8854. "harddisk" ":TYPE_INSTALL_MEDIUM_HARDDISK:" \\
  8855. "network" ":TYPE_INSTALL_MEDIUM_NETWORK:" \\
  8856. EOF
  8857. }
  8858.  
  8859. Build_PKG()
  8860. {
  8861.   touch /tmp/LST/HOPE
  8862.   cat /tmp/LST/HOPE
  8863.   rm -f /tmp/LST/HOPE
  8864. }
  8865.  
  8866. Build_PKG_Info()
  8867. {
  8868.   build_menu -f -d $FILE_PKGS_DATA
  8869. }
  8870.  
  8871. Build_PKG_Installed()
  8872. {
  8873.   build_menu -f -d $FILE_PKGS_DATA
  8874. }
  8875.  
  8876. Check_Pkg_Database()
  8877. {
  8878.   if [ -z "$FILE_PKGS_DATA" ]; then
  8879.     Msg ":ERR_MISSING_PKG_DATABASE_FILE_NAME:"
  8880.     return 1        
  8881.   fi
  8882.   if [ ! -f "$FILE_PKGS_DATA" ]; then
  8883.     Msg ":ERR_MISSING_PKG_DATABASE:"
  8884.     return 1        
  8885.   fi
  8886.   return 0
  8887. }
  8888.  
  8889. Check_Pkg_Index()
  8890. {
  8891.   if [ -z "$FILE_PKGS_INDEX" ]; then
  8892.     Msg ":ERR_MISSING_PKG_INDEX_FILE_NAME:"
  8893.     return 1        
  8894.   fi
  8895.   if [ ! -f "$FILE_PKGS_INDEX" ]; then
  8896.     Msg ":ERR_MISSING_PKG_INDEX:"
  8897.     return 1        
  8898.   fi
  8899.   return 0
  8900. }
  8901.  
  8902. Choose_Install_Source()
  8903. {
  8904.     while [ 1 ]; do 
  8905.         rm -f /source
  8906.         if [ -n "`mount | fgrep /mnt/install | fgrep ':'`" ]; then
  8907.             ANSWER="network"
  8908.         else
  8909.             ANSWER="cdrom"
  8910.         fi
  8911.         CONF_INSTALL_MEDIUM="$ANSWER"
  8912.         Debug "CONF_INSTALL_MEDIUM=<$CONF_INSTALL_MEDIUM>"
  8913.         Do_Store CONF_INSTALL_MEDIUM "$CONF_INSTALL_MEDIUM"
  8914.         case $CONF_INSTALL_MEDIUM in
  8915.         network)
  8916.             CONF_INSTALL_DEV="`mount | fgrep /mnt/install | cut -d':' -f 1`"
  8917.             Is_Known_Source /mnt/install || continue
  8918.             ;;
  8919.         cdrom)
  8920.             CONF_INSTALL_DEV="`mount | fgrep /mnt/install | cut -d' ' -f 1`"
  8921.             ln -sf $CONF_INSTALL_DEV /dev/cdrom
  8922.             Is_Known_Source /mnt/install || continue
  8923.             ;;
  8924.         esac
  8925.         ln -sf $DIR_SOURCE /source
  8926.         break
  8927.     done
  8928.     Do_Store CONF_INSTALL_DEV "$CONF_INSTALL_DEV"
  8929.     Do_Store CONF_INSTALL_PATH_SRC "$CONF_INSTALL_PATH_SRC"
  8930.     Do_Store DIR_SOURCE "$DIR_SOURCE"
  8931.     Do_Store DIR_PKGS "$DIR_PKGS"
  8932.     return 0
  8933. }
  8934.  
  8935. Do_Reverse()
  8936. {
  8937.     local rev_string=""
  8938.     local i
  8939.  
  8940.     if [ $# -eq 0 ]; then
  8941.         echo ""
  8942.         return 0
  8943.     fi
  8944.     for i in $@ ; do
  8945.         rev_string="$i $rev_string"
  8946.     done
  8947.     echo $rev_string
  8948.     return 0
  8949. }
  8950.  
  8951. Choose_Install_Target()
  8952. {
  8953.     local partition
  8954.     local mountpoint
  8955.     local dummy
  8956.     local root_mounted
  8957.     local root_last
  8958.     local root_conf
  8959.     local try_root
  8960.     local mke2fs_retval
  8961.     local devs_under_root=""
  8962.     local devs_under_root_rev=""
  8963.     local auto_target="`Get_Val CONF_INSTALL_ROOT`"
  8964.     local i
  8965.  
  8966.         rm -f $FILE_TARGETS_SEL
  8967.     while [ 1 ]; do
  8968.     partition=
  8969.     mountpoint=/root
  8970.     dummy=
  8971.     root_mounted=
  8972.     root_last=
  8973.     root_conf=
  8974.     try_root=
  8975.  
  8976.     Debug "Choose_Install_Target called."
  8977.     if [ -f /tmp/root.fix ]; then
  8978.         CONF_INSTALL_ROOT="`cat /tmp/root.fix`"
  8979.         DIR_TARGET="`Get_Val DIR_TARGET`"
  8980.     else
  8981.         # start of not indended area...
  8982.  
  8983.     # check whether we have any target partition at all
  8984.     if [ -z "`sysinfo -C Dest --notitle --noheader --partition`" ]; then
  8985.         Error2 NO_TARGET_AVAILABLE
  8986.         ANSWER="new"
  8987.         return 0
  8988.     fi
  8989.  
  8990.     # check whether there is something mounted on $mountpoint
  8991.     Check_Directory_Busy $mountpoint || root_mounted="$STATUS"
  8992.  
  8993.     CONF_INSTALL_ROOT=
  8994.     rm -f $FILE_ROOT_SEL.not
  8995.     touch $FILE_ROOT_SEL.not
  8996.     for i in $root_mounted $root_last $root_conf ; do
  8997.         cat $FILE_ROOT_SEL.not | fgrep -x "$i" >/dev/null && continue
  8998.         # ask whether we want to use this
  8999.         # FIXME: hardcoded strings
  9000.         $CMD_BOX --default "j" --bool "The partition $i ; :ASK_USE_AS_ROOT_PARTITION:" 2> $FILE_TMP_ANSWER || return 1
  9001.         if [ "`cat $FILE_TMP_ANSWER`" = "0" ]; then
  9002.             try_root="$i"
  9003.             break
  9004.         else
  9005.             echo "$i" >> $FILE_ROOT_SEL.not
  9006.         fi
  9007.     done
  9008.     rm -f $FILE_ROOT_SEL.not
  9009.  
  9010.     # first unmount any partitions below /root in reverse order
  9011.     devs_under_root="`mount | sed -n '/on \/root\//p' | cut -d' ' -f 1`"
  9012.     if [ -n "$devs_under_root" ]; then
  9013.         devs_under_root_rev="`Do_Reverse "$devs_under_root"`"
  9014.         if [ -n "$devs_under_root_rev" ]; then
  9015.             for i in $devs_under_root_rev ; do
  9016.                 Do_Umount $i
  9017.             done
  9018.         fi
  9019.     fi
  9020.  
  9021.     # unmount old partitions
  9022.     touch $FILE_TARGETS_SEL
  9023.     for i in `cat $FILE_TARGETS_SEL` ; do
  9024.         # do not unmount new root partition
  9025.         if [ "$i" = "$CONF_INSTALL_ROOT" ]; then
  9026.             continue
  9027.         fi
  9028.         # do not unmount source device
  9029.         if [ "$i" = "$CONF_INSTALL_DEV" ]; then
  9030.             continue
  9031.         fi
  9032.         # do not unmount swap partitions
  9033.         if [ -f $FILE_SWAP_SEL ]; then
  9034.             fgrep -x "$i" $FILE_SWAP_SEL >/dev/null
  9035.             if [ $? -eq 0 ]; then
  9036.                 continue
  9037.             fi
  9038.         fi
  9039.         Do_Umount $i
  9040.     done
  9041.  
  9042.     # ask for target root partition
  9043.     while [ 1 ]; do
  9044.         CONF_INSTALL_ROOT=
  9045.         if [ -n "$try_root" ]; then
  9046.             CONF_INSTALL_ROOT="$try_root"
  9047.             try_root=
  9048.             fs_type="`mount | sed -n '/on \/root /s/.*type \([^ ]*\) .*/\1/p'`"
  9049.             break
  9050.         else
  9051.             # umsdos source and target IMPOSSIBLE!
  9052.             Debug "FTS: appended '$CONF_INSTALL_DEV'"
  9053.             echo "$CONF_INSTALL_DEV" >> $FILE_TARGETS_SEL
  9054.             Choose --menutitle ":CHOOSE_PARTITION_MENUTITLE:" --build "Build_PARTITION --exclude $FILE_TARGETS_SEL DestSorted" PARTITION_ROOT $auto_target || return 1
  9055.             if [ -z "$ANSWER" ]; then
  9056.                 Error "no partition specified!"
  9057.                 continue
  9058.             else
  9059.                 CONF_INSTALL_ROOT="$ANSWER"
  9060.             fi
  9061.         fi
  9062.         partid="`Get_Partition_Info --id $CONF_INSTALL_ROOT`"
  9063.         if [ "$partid" = "1" -o "$partid" = "4" -o "$partid" = "6" ]; then
  9064.             Warn "Partition $CONF_INSTALL_ROOT ; :WARN_USE_UMSDOS:" || continue
  9065.             Do_Mount -t umsdos $CONF_INSTALL_ROOT /root || continue
  9066.             fs_type="$ANSWER"
  9067.             if [ "$fs_type" = "umsdos" ]; then
  9068.                 if [ -d /root/linux ]; then
  9069.                     Ask_Bool --pretext "Partition $CONF_INSTALL_ROOT ; " DELETE_LINUX_SUBDIR || return 1
  9070.                     if [ "$ANSWER" = "0" ]; then
  9071.                         rm -fr /root/linux
  9072.                     else
  9073.                         Warn "Partition $CONF_INSTALL_ROOT ; :WARN_NOT_USABLE_AS_ROOT:"
  9074.                         return 1
  9075.                     fi
  9076.                 fi
  9077.                 mkdir -p /root/linux/etc
  9078.                 touch /root/linux/etc/rc
  9079.                 prep_use UMSDOS
  9080.                 umssync -r99 -v- /root/linux >>$FILE_LOG_HISTORY 2>&1
  9081.                 end_use UMSDOS
  9082.                 DIR_TARGET=/root/linux
  9083.                 mkdir -p $DIR_TARGET/var/adm/LST/log
  9084.                 PATH=${PATH}:$DIR_TARGET/bin:$DIR_TARGET/usr/bin:$DIR_TARGET/sbin:$DIR_TARGET/usr/sbin
  9085.                 export PATH
  9086.                 break
  9087.             else
  9088.                 Error "DOS Partition was not mounted as type umsdos but as type $fs_type"
  9089.                 Do_Umount /root
  9090.                 continue
  9091.             fi
  9092.         elif [ "$partid" = "131" ]; then
  9093.             # do not format partitions that contain a swap file
  9094.             ROOT_INITIALIZED=0
  9095.             Check_Found "$CONF_INSTALL_ROOT" "$FILE_SWAP_SEL"
  9096.             if [ $? -ne 0 ]; then
  9097.                 # otherwise force format for root partition
  9098.                 Do_Umount $CONF_INSTALL_ROOT || continue
  9099.                 Do_Umount /root || continue
  9100.                 Menu_Call_Mke2fs "$CONF_INSTALL_ROOT" || continue
  9101.             fi
  9102.             Do_Mount -t ext2 $CONF_INSTALL_ROOT /root || continue
  9103.             fs_type="$ANSWER"
  9104.             DIR_TARGET=/root
  9105.             mkdir -p $DIR_TARGET/var/adm/LST/log
  9106.             break
  9107.         else
  9108.             Error "a partition with type <$partid> can not be used as root-partition!"
  9109.             continue
  9110.         fi
  9111.     done
  9112.     Debug "FTS: appending '$CONF_INSTALL_ROOT'"
  9113.     echo "$CONF_INSTALL_ROOT" >> $FILE_TARGETS_SEL
  9114.     echo "$CONF_INSTALL_ROOT" > $FILE_ROOT_SEL
  9115.     # we don't need to ask for a mount point here as it's implicit for root
  9116.     mkdir -p $DIR_TARGET/proc
  9117.     mkdir -p $DIR_TARGET/etc    
  9118.     echo "$CONF_INSTALL_ROOT / $fs_type defaults 0 1" > $DIR_TARGET/etc/fstab
  9119.     echo "/proc /proc proc defaults 0 0" >> $DIR_TARGET/etc/fstab
  9120.     if [ -s $FILE_SWAP_SEL ]; then
  9121.         if [ -s /tmp/fstab.tmp ]; then
  9122.             cat /tmp/fstab.tmp >> $DIR_TARGET/etc/fstab
  9123.         else
  9124.             echo "`cat $FILE_SWAP_SEL` none swap defaults 0 0" >> $DIR_TARGET/etc/fstab
  9125.         fi
  9126.         Debug "FTS: appending '$FILE_SWAP_SEL'"
  9127.         cat $FILE_SWAP_SEL >> $FILE_TARGETS_SEL
  9128.     fi
  9129.     chmod 644 $DIR_TARGET/etc/fstab
  9130.  
  9131.         # end of not indended area
  9132.     fi
  9133.     Do_Store CONF_INSTALL_ROOT "$CONF_INSTALL_ROOT"
  9134.     Do_Store DIR_TARGET "$DIR_TARGET"
  9135.  
  9136.     # ask for additional target partitions
  9137.     while [ 1 ]; do
  9138.         if [ -z "`Build_PARTITION --exclude $FILE_TARGETS_SEL Linux`" ];then
  9139.             Debug --diskonly "No ADDITIONAL partitions available"
  9140.             return 0
  9141.         fi
  9142.         Ask_Bool MORE_TARGET_PARTITIONS n || break
  9143.         if [ "$ANSWER" = "1" ]; then
  9144.             return 0
  9145.         fi
  9146.         Choose --menutitle ":CHOOSE_PARTITION_MENUTITLE:" --build "Build_PARTITION --exclude $FILE_TARGETS_SEL Linux" PARTITION_OTHER
  9147.         if [ -z "$ANSWER" ]; then
  9148.             Error "no partition specified!"
  9149.             continue
  9150.         elif [ "$ANSWER" = "new" ]; then
  9151.             return 0
  9152.         else
  9153.             partition="$ANSWER"
  9154.         fi
  9155.         while [ 1 ]; do
  9156.             Ask_String MOUNTPOINT || continue
  9157.             if [ -n "$ANSWER" ]; then
  9158.                 # make PATH absolute
  9159.                 echo "$ANSWER" | cut -c 1 | fgrep '/' >/dev/null || ANSWER="/$ANSWER"
  9160.                 break
  9161.             else
  9162.                 Error "no mount point specified"
  9163.             fi
  9164.         done
  9165.         mountpoint="$ANSWER"
  9166.  
  9167.         partid="`Get_Partition_Info --id $partition`"
  9168.         if [ "$partid" = "131" ]; then
  9169.             Menu_Call_Mke2fs "$partition"
  9170.             mke2fs_retval=$?
  9171.             if [ $mke2fs_retval -eq 2 ] ; then
  9172.                 # we did not want to format it
  9173.                 # can we mount it?
  9174.                 mkdir -p /tmp/mnt
  9175.                 mount -r -t ext2 $partition /tmp/mnt >/dev/null 2>&1
  9176.                 if [ $? -eq 0 ]; then
  9177.                     umount /tmp/mnt >/dev/null 2>&1
  9178.                     Ask_Bool --pretext "Partition $partition ; " MOUNT_INSTEAD_FORMAT || continue
  9179.                     if [ "$ANSWER" = "0" ]; then
  9180.                         Warn ":WARN_PARTITION_NOT_FORMATED:" || continue
  9181.                     else
  9182.                         continue
  9183.                     fi
  9184.                 fi
  9185.             else
  9186.                 if [ $mke2fs_retval -ne 0 ] ; then continue ; fi
  9187.             fi
  9188.         fi
  9189.         mkdir -p ${DIR_TARGET}$mountpoint
  9190.         Do_Mount "$partition" ${DIR_TARGET}$mountpoint || continue
  9191.         fs_type="$ANSWER"
  9192.         echo "$partition" > $FILE_TARGETS_SEL.tmp
  9193.         if [ ! -f $FILE_TARGETS_SEL ]; then
  9194.             Panic "no root partition specified!"
  9195.             return 1
  9196.         fi
  9197.         cat $FILE_TARGETS_SEL >> $FILE_TARGETS_SEL.tmp
  9198.         mv $FILE_TARGETS_SEL.tmp $FILE_TARGETS_SEL
  9199.         Debug "FTS: setting '`cat $FILE_TARGETS_SEL`'"
  9200.         echo "$partition $mountpoint $fs_type defaults 0 2" >> $DIR_TARGET/etc/fstab
  9201.         mkdir -p $DIR_TARGET/var/adm/LST/log
  9202.       done # other choose loop
  9203.     done # target choose loop
  9204.     return 0
  9205. }
  9206.  
  9207. # checks if CD is valid and writes version to Debug
  9208. #
  9209. Do_Analyse_CD()
  9210. {
  9211.   local cd_label=
  9212.   local smarties_retval=
  9213.  
  9214.   if [ -x /usr/lib/LST/smarties ]; then
  9215.     /usr/lib/LST/smarties $CONF_INSTALL_DEV > /tmp/.version
  9216.     smarties_retval=$?
  9217.     cd_label="`cat /tmp/.version`"
  9218.  
  9219.     # continue if smarties has internal problems (driver errors on seek/read)
  9220.     if [ $smarties_retval -eq 3 ]; then
  9221.       return 0
  9222.     fi
  9223.  
  9224.     # abort if unknown CD was detected
  9225.     if [ -z "$cd_label" ]; then
  9226.       Debug "CDROM is unknown"
  9227.       #Do_Umount /mnt
  9228.       Error2 NO_ORIG_CD
  9229.       #Ask_Bool CONTINUE_INSTALL n
  9230.       #if [ "$ANSWER" = "0" ]; then
  9231.     return 0
  9232.       #fi
  9233.       #return 1
  9234.     else
  9235.       Debug "CDROM is <$cd_label>"
  9236.       if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" != "SBA" ]; then
  9237.         Msg ":INFO_KNOWN_CD_DETECTED: ; ; $cd_label"
  9238.         if [ "$cd_label" = "Toolbox Linux Sonderheft 1997" ]; then
  9239.           Msg ":INFO_TOOLBOX_CD:"
  9240.         fi
  9241.       fi
  9242.     fi
  9243.  
  9244.     # abort if a non install CD was inserted
  9245.     if [ $smarties_retval -ne 0 ]; then
  9246.       Debug "wrong CD inserted"
  9247.       Do_Umount /mnt
  9248.       Error2 NO_INSTALL_CD
  9249.       return 1
  9250.     else
  9251.       return 0
  9252.     fi
  9253.   fi
  9254. }
  9255.  
  9256. MountModulesFloppy()
  9257. {
  9258.   local modpath="/lib/modules"
  9259.   local success=
  9260.  
  9261.   mount /floppy >/dev/null 2>&1
  9262.   while [ 1 ]; do
  9263.     if [ -d /floppy/$modpath ]; then
  9264.       success=true
  9265.       break
  9266.     else
  9267.       umount /floppy >/dev/null 2>&1
  9268.       Msg ":DO_INSERT_MODULES_FLOPPY:" || break
  9269.       mount /floppy >/dev/null 2>&1
  9270.     fi
  9271.   done
  9272.   if [ -n "$success" ]; then
  9273.     return 0
  9274.   else
  9275.     return 1
  9276.   fi
  9277. }
  9278.  
  9279. # checks if source path is valid and sets
  9280. # CONF_INSTALL_PATH_SRC
  9281. # DIR_BIN
  9282. # DIR_DATA
  9283. # DIR_SOURCE
  9284. # DIR_PKGS
  9285. #
  9286. Is_Known_Source()
  9287. {
  9288.   local prefix="/mnt" # during install the source is mounted under /mnt
  9289.   local suffix="install/basis1/basis1.idx"
  9290.  
  9291.   if [ $# -gt 0 ]; then
  9292.     prefix="$1" # later we may specify a different path
  9293.   fi
  9294.  
  9295.   while [ 1 ]; do
  9296.     export DIR_BIN=
  9297.     export DIR_DATA=
  9298.     export DIR_PKGS=
  9299.  
  9300.     if [ -d $prefix/install -a -d $prefix/bin -a -d $prefix/data ]; then
  9301.       Debug "found Caldera OpenLinux / LST Power Linux"
  9302.       CONF_INSTALL_PATH_SRC=""
  9303.       DIR_SOURCE="$prefix"
  9304.       DIR_DATA="$DIR_SOURCE/data"
  9305.       DIR_BIN="$DIR_SOURCE/bin"
  9306.       DIR_PKGS="$DIR_SOURCE/install"
  9307.       return 0
  9308.     elif [ -f $prefix/col/data/cd1 ]; then
  9309.       Debug "found Caldera OpenLinux 1.2 CD 1"
  9310.       CONF_INSTALL_PATH_SRC="col"
  9311.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9312.       DIR_DATA="$DIR_SOURCE/data"
  9313.       if [ -f $DIR_DATA/pkgs.db ]; then
  9314.         cp -a $DIR_DATA/pkgs.db $FILE_PKGS_DATA
  9315.       fi
  9316.       DIR_BIN="$DIR_SOURCE/bin"
  9317.       DIR_PKGS="$DIR_SOURCE/install"
  9318.       return 0
  9319.     elif [ -f $prefix/col/data/cd2 ]; then
  9320.       Debug "found Caldera OpenLinux 1.2 CD 2"
  9321.       CONF_INSTALL_PATH_SRC="col"
  9322.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9323.       DIR_DATA="$DIR_SOURCE/data"
  9324.       if [ -f $DIR_DATA/pkgs.db ]; then
  9325.         cp -a $DIR_DATA/pkgs.db $FILE_PKGS_DATA
  9326.       fi
  9327.       DIR_BIN="$DIR_SOURCE/bin"
  9328.       DIR_PKGS="$DIR_SOURCE/install"
  9329.       return 0
  9330.     elif [ -d $prefix/col/lib ]; then
  9331.       Debug "found Caldera OpenLinux 1.2"
  9332.       CONF_INSTALL_PATH_SRC="col"
  9333.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9334.       DIR_DATA="$DIR_SOURCE/data"
  9335.       DIR_BIN="$DIR_SOURCE/bin"
  9336.       DIR_PKGS="$DIR_SOURCE/install"
  9337.       return 0
  9338.     elif [ -f $prefix/col/$suffix ]; then
  9339.       Debug "found Caldera OpenLinux 1.1"
  9340.       INSTALL_MODE=LST
  9341.       CONF_INSTALL_PATH_SRC="col"
  9342.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9343.       DIR_DATA="$DIR_SOURCE/data"
  9344.       DIR_BIN="$DIR_SOURCE/bin"
  9345.       DIR_PKGS="$DIR_SOURCE/install"
  9346.       return 0
  9347.     elif [ -f $prefix/col_10/$suffix ]; then
  9348.       Debug "found Caldera OpenLinux 1.0"
  9349.       CONF_INSTALL_PATH_SRC="col_10"
  9350.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9351.       DIR_DATA="$DIR_SOURCE/data"
  9352.       DIR_BIN="$DIR_SOURCE/bin"
  9353.       DIR_PKGS="$DIR_SOURCE/install"
  9354.       return 0
  9355.     elif [ -f $prefix/col_10b/$suffix ]; then
  9356.       Debug "found Caldera OpenLinux 1.0 Beta Preview"
  9357.       CONF_INSTALL_PATH_SRC="col_10b"
  9358.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9359.       DIR_DATA="$DIR_SOURCE/data"
  9360.       DIR_BIN="$DIR_SOURCE/bin"
  9361.       DIR_PKGS="$DIR_SOURCE/install"
  9362.       return 0
  9363.     elif [ -f $prefix/lst_22/$suffix ]; then
  9364.       Debug "found LST 2.2 Power Linux"
  9365.       CONF_INSTALL_PATH_SRC="lst_22"
  9366.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9367.       DIR_DATA="$DIR_SOURCE/data"
  9368.       DIR_BIN="$DIR_SOURCE/bin"
  9369.       DIR_PKGS="$DIR_SOURCE/install"
  9370.       return 0
  9371.     elif [ -f $prefix/lst_22b/$suffix ]; then
  9372.       Debug "found LST 2.2 Beta Preview"
  9373.       CONF_INSTALL_PATH_SRC="lst_22b"
  9374.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9375.       DIR_DATA="$DIR_SOURCE/data"
  9376.       DIR_PKGS=$DIR_SOURCE
  9377.       return 0
  9378.     elif [ -f $prefix/lst_21/$suffix ]; then
  9379.       Debug "found LST 2.1 Power Linux"
  9380.       CONF_INSTALL_PATH_SRC="lst_21"
  9381.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9382.       DIR_DATA="$DIR_SOURCE"
  9383.       DIR_PKGS=$DIR_SOURCE
  9384.       return 0
  9385.     elif [ -f $prefix/Packages/RPMS/calderize-1.0-1.i386.rpm ]; then
  9386.       Debug "found Caldera Network Desktop 1.0"
  9387.       CONF_INSTALL_PATH_SRC="Packages"
  9388.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  9389.       DIR_PKGS=$DIR_SOURCE
  9390.       export CND10_MODE=true
  9391.       Msg ":INFO_CND10_WILL_REQUIRE_MODULES_FLOPPY:"
  9392.       MountModulesFloppy
  9393.       return 0
  9394.     else
  9395.       Debug "no known Distribution found under <$prefix>"
  9396.       Error "<$prefix> ; :ERR_INVALID_SOURCE_PATH:"
  9397.       Ask_String DIR_SOURCE "$prefix" || return 1
  9398.       prefix="$ANSWER"
  9399.     fi
  9400.   done
  9401. }
  9402.  
  9403. Do_Calc_Freespace()
  9404. {
  9405.     local i=
  9406.     local PathRegexProof
  9407.     local master_mntpoint
  9408.     local sub_mntpoints
  9409.  
  9410.     FREESPACE=0
  9411.     rm -f $FILE_TMP_VAL
  9412.  
  9413.     if [ $# -eq 0 ]; then
  9414.         PathRegexProof="\/"
  9415.     else
  9416.         PathRegexProof="`echo "$1" | sed 's/\//\\\\\//'`"
  9417.     fi
  9418.  
  9419.     Debug "PathRegexProof=<$PathRegexProof>"
  9420.  
  9421.     # get list of mountpoints for the specified path
  9422.     master_mntpoint="`mount | sed -n '/on '${PathRegexProof}' /p' | cut -d' ' -f 3`"
  9423.     Debug "master_mntpoint=<$master_mntpoint>"
  9424.     if [ -n "$master_mntpoint" ]; then
  9425.         df $master_mntpoint | fgrep '%' | cut -c 37-45 > $FILE_TMP_VAL
  9426.     else
  9427.         # specified path is not a directory. use simple df on its fs
  9428.         df $1 | fgrep '%' | cut -c 37-45 > $FILE_TMP_VAL
  9429.     fi
  9430.  
  9431.     sub_mntpoints="`mount | sed -n '/on '${PathRegexProof}'\//p' | cut -d' ' -f 3`"
  9432.     Debug "sub_mntpoints=<$sub_mntpoints>"
  9433.     if [ -n "$sub_mntpoints" ]; then
  9434.         for i in $sub_mntpoints ; do
  9435.             df $i | fgrep '%' | cut -c 37-45 >> $FILE_TMP_VAL
  9436.         done
  9437.     fi
  9438.  
  9439.     touch $FILE_TMP_VAL
  9440.     for i in `cat $FILE_TMP_VAL` ; do
  9441.         FREESPACE="`do_calc $FREESPACE + $i`"
  9442.     done
  9443.     FREESPACE="`do_calc $FREESPACE \* 1024`"
  9444.     if [ -z "$FREESPACE" ]; then
  9445.         FREESPACE=0
  9446.     fi
  9447.     Debug "summarized FREESPACE=<$FREESPACE>"
  9448.  
  9449.     export FREESPACE
  9450.     return 0
  9451. }
  9452.  
  9453. # calculate space requirements for a given list of packages
  9454. Do_Calc_Needspace()
  9455. {
  9456.   export NEEDSPACE=0
  9457.   local sellist=$1
  9458.  
  9459.   NEEDSPACE="`build_menu -t $sellist -d $FILE_PKGS_DATA -S | cut -d':' -f 7`"
  9460.   NEEDSPACE="`do_calc $NEEDSPACE \* 1024`"
  9461.   Debug "NEEDSPACE => <$NEEDSPACE>" 
  9462. }
  9463.  
  9464. Do_Find_File_To_Pkg()
  9465. {
  9466.   local f_name=Do_Find_File_To_Pkg
  9467.   local f_args=1 # (pkg) -> PKG_FILE
  9468.   local tmpfile=/tmp/pkginfo.$$
  9469.   local pkg="$1"
  9470.   local vers
  9471.   local subdir
  9472.   local pkgpath="$DIR_PKGS/RPMS"
  9473.   export PKG_FILE=unknown
  9474.  
  9475.   Check_Args $f_name $f_args $# "$@" || return 255
  9476.  
  9477.   # get version from pkgs.db
  9478.   db_printf -n -m ":1:$pkg:" -p ":-8:" -f $FILE_PKGS_DATA | sed 's/[     ]*//g' > $tmpfile
  9479.   if [ -s $tmpfile ]; then
  9480.     read vers < $tmpfile
  9481.   fi
  9482.   rm -f $tmpfile
  9483.  
  9484.   Debug "Do_Find_File_To_Pkg $1 -> $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm"
  9485.   if [ -f $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm ]; then
  9486.     # first we look for rpm files
  9487.     PKG_FILE="$pkgpath/$pkg-$vers.${RPMBINEXT}.rpm"
  9488.     Debug "found PKG_FILE=$PKG_FILE (rpm case)"
  9489.     return 0
  9490.   elif [ -f $pkgpath/$pkg-$vers.${RPMBINEXT2}.rpm ]; then # bug 84 - jwc
  9491.     # first we look for rpm files
  9492.     PKG_FILE="$pkgpath/$pkg-$vers.${RPMBINEXT2}.rpm"
  9493.     Debug "found PKG_FILE=$PKG_FILE (rpm case)"
  9494.     return 0
  9495.   elif [ -f $pkgpath/$pkg-$vers.${RPMBINEXT3}.rpm ]; then
  9496.     # first we look for rpm files
  9497.     PKG_FILE="$pkgpath/$pkg-$vers.${RPMBINEXT3}.rpm"
  9498.     Debug "found PKG_FILE=$PKG_FILE (rpm case)"
  9499.     return 0
  9500.   elif [ -f $pkgpath/$pkg-$vers.${RPMBINEXT4}.rpm ]; then
  9501.     # first we look for rpm files
  9502.     PKG_FILE="$pkgpath/$pkg-$vers.${RPMBINEXT4}.rpm"
  9503.     Debug "found PKG_FILE=$PKG_FILE (rpm case)"
  9504.     return 0
  9505.   else
  9506.     # support harddisk installs from msdos partitions
  9507.     # get subdir from pkgs.db
  9508.     db_printf -n -m ":1:$pkg:" -p ":-6:" -f $FILE_PKGS_DATA | sed 's/[     ]*//g' > $tmpfile
  9509.     if [ -s $tmpfile ]; then
  9510.       read subdir < $tmpfile
  9511.     fi
  9512.     rm -f $tmpfile
  9513.     Debug "Trying trans.tbl lookup for $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm"
  9514.     Do_Lookup_Trans_Tbl $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm
  9515.     if [ $? -eq 0 ]; then
  9516.       PKG_FILE="$ANSWER"
  9517.     else
  9518.       if [ -d $DIR_PKGS/$subdir ]; then
  9519.         pkgpath=$DIR_PKGS/$subdir
  9520.       fi
  9521.       Debug "Trying trans.tbl lookup for $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm"
  9522.       Do_Lookup_Trans_Tbl $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm
  9523.       if [ $? -eq 0 ]; then
  9524.         PKG_FILE="$ANSWER"
  9525.       else
  9526.         Error "$pkgpath/$pkg-$vers.${RPMBINEXT}.rpm ; :ERR_FILE_NOT_FOUND:"
  9527.         echo "$pkgpath/$pkg-$vers.${RPMBINEXT}.rpm not found" >> /root/tmp/LST/install_error
  9528.         Ask_Bool ABORT_INSTALL y
  9529.         if [ "$ANSWER" = "0" ]; then
  9530.       Do_Reboot
  9531.         fi
  9532.         Is_Expert
  9533.         if [ $? -eq 0 ]; then
  9534.           echo "Enter Path"
  9535.           read PKG_FILE
  9536.           export PKG_FILE
  9537.         fi
  9538.       fi
  9539.     fi
  9540.     return 1
  9541.   fi
  9542. }
  9543.  
  9544. Do_Find_Pkg_To_File()
  9545. {
  9546.     local f_name=Do_Find_Pkg_To_File
  9547.     local f_args=1 # (file) -> PKG_NAME
  9548.     local file="$1"
  9549.  
  9550.     Get_Pkg_Type $file || return 1
  9551.     case $PKG_TYPE in
  9552.     rpm)
  9553.         # rpm package
  9554.         if [ "$CND10_MODE" = "true" ]; then
  9555.             # old rpmextr version
  9556.             rpmextr --shell $file | fgrep PKG_NAME > $FILE_TMP_VAL
  9557.             . $FILE_TMP_VAL
  9558.         else
  9559.             # new rpmextr version
  9560.             PKG_NAME="`rpmextr --tag=name $file`"
  9561.         fi
  9562.         ;;
  9563.     esac
  9564.     export PKG_NAME
  9565.     Debug "Do_Find_Pkg_To_File $1 -> $PKG_NAME"
  9566.     return 0
  9567. }
  9568.  
  9569. # FIXME: this is a really bad hack. We need dependencies...
  9570. Do_Sort_Pkgs()
  9571. {
  9572.     local i
  9573.     local first_pkgs="DEV MAKEDEV dev grep sed ld.so glibc libc aout-libs bash lisa fileutils sh-utils textutils util-linux make"
  9574.  
  9575.     # resort pkglist to make sure essential packages are installed first
  9576.     Debug "resorting selected packages"
  9577.     rm -f $FILE_PKGS_SEL.tmp
  9578.     touch $FILE_PKGS_SEL
  9579.     touch $FILE_PKGS_SEL.tmp
  9580.     for i in $first_pkgs `cat $FILE_PKGS_SEL` ; do
  9581.         fgrep -x $i $FILE_PKGS_SEL > /dev/null
  9582.         if [ $? -eq 0 ]; then
  9583.             fgrep -x $i $FILE_PKGS_SEL.tmp > /dev/null
  9584.             if [ $? -ne 0 ]; then
  9585.                 echo "$i" >> $FILE_PKGS_SEL.tmp
  9586.             fi
  9587.         fi
  9588.     done
  9589.     mv $FILE_PKGS_SEL.tmp $FILE_PKGS_SEL
  9590. }
  9591.  
  9592.  
  9593. Do_Sort_Series()
  9594. {
  9595.     local i
  9596.  
  9597.     # resort serieslist to make sure basis and xbasis are installed first
  9598.     mv $FILE_SERIES_SEL $FILE_SERIES_SEL.tmp
  9599.     touch $FILE_SERIES_SEL
  9600.     for i in $LST_SERIES ; do
  9601.         fgrep $i $FILE_SERIES_SEL.tmp > /dev/null
  9602.         if [ $? -eq 0 ]; then
  9603.             echo "$i" >> $FILE_SERIES_SEL
  9604.         fi
  9605.     done
  9606.     rm -f $FILE_SERIES_SEL.tmp
  9607. }
  9608.  
  9609. Do_Transfer_Minimum()
  9610. {
  9611.     local i
  9612.  
  9613.     mkdir -p $DIR_TARGET/bin
  9614.     cp -a /bin/cat /bin/mkdir /bin/basename $DIR_TARGET/bin
  9615.  
  9616.     mkdir -p $DIR_TARGET/lib
  9617.     cp -a /lib/libc.so.4.5.24 $DIR_TARGET/lib
  9618.     ln -sf libc.so.4.5.24 $DIR_TARGET/lib/libc.so.4
  9619.  
  9620.     mkdir -p $DIR_TARGET/etc/rc.d
  9621.     for i in rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d ; do
  9622.         mkdir -p $DIR_TARGET/etc/rc.d/$i
  9623.     done
  9624. }
  9625.  
  9626. Do_Pkg_Install()
  9627. {
  9628.     local myseries=
  9629.     local mydisk=
  9630.     local pkgname=
  9631.     local pkgfile=
  9632.  
  9633.     Debug "Do_Pkg_Install <$@>"
  9634.     Has_Source || return 1
  9635.     Has_Target_Path || return 1
  9636.     Has_Selections || return 1
  9637.  
  9638.     prep_use INSTALL || return 1
  9639.     prep_use RPM_INSTALL || return 1
  9640.  
  9641.     Do_Sort_Pkgs
  9642.     Do_Sort_Series
  9643.     build_menu -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA -n -p ":5:" > $FILE_DISKS_SEL
  9644.   
  9645.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" != "SBA" ]; then
  9646.         Msg2 PKG_INSTALL || continue
  9647.     fi
  9648.  
  9649.     Info ":INFO_WAIT:"
  9650.  
  9651.     # After this point there is no way to stop the installation
  9652.     # and to step back so we can safely delete and move some things
  9653.     # to avoid running out of ramdisk space
  9654.     
  9655.     # Copy minimal files from ramdisk to root
  9656.     Do_Transfer_Minimum
  9657.  
  9658.     # Delete the unused modules from the ramdisk
  9659.     Delete_unused_modules
  9660.  
  9661.     # switch the log area
  9662.     Do_Switch_Log_Area
  9663.  
  9664.     # mount /proc additionally under $DIR_TARGET to make sure
  9665.     # the /dev/core symlink points to something usefull
  9666.     mkdir -p $DIR_TARGET/proc
  9667.     mount -t proc /proc $DIR_TARGET/proc
  9668.     
  9669.     export DIR_LOG_PKGS=$DIR_TARGET/install
  9670.     export DIR_LOG_INSTALLED=$DIR_LOG_PKGS/installed
  9671.     export DIR_LOG_CATALOG=$DIR_LOG_PKGS/catalog
  9672.     export DIR_LOG_CONTENTS=$DIR_LOG_PKGS/contents
  9673.     export DIR_LOG_CONFLICTS=$DIR_LOG_PKGS/conflicts
  9674.     export DIR_LOG_SCRIPTS=$DIR_LOG_PKGS/scripts
  9675.     export DIR_LOG_DISKS=$DIR_LOG_PKGS/disks
  9676.     export DIR_LOG_SAVED=$DIR_LOG_PKGS/saved
  9677.     export DIR_LOG_REPLACED=$DIR_LOG_PKGS/replaced
  9678.     export DIR_LOG_DELETED=$DIR_LOG_PKGS/deleted
  9679.     export DIR_LOG_ERRORS=$DIR_LOG_PKGS/errors
  9680.     for logdir in $DIR_LOG_ANALYSE $DIR_LOG_LOG $DIR_LOG_INSTALLED $DIR_LOG_SCRIPTS $DIR_LOG_DISKS $DIR_LOG_CATALOG $DIR_LOG_CONTENTS $DIR_LOG_CONFLICTS $DIR_LOG_SAVED $DIR_LOG_REPLACED $DIR_LOG_DELETED $DIR_LOG_ERRORS ; do
  9681.         mkdir -p $logdir
  9682.     done
  9683.  
  9684.     Get_Install_Stat
  9685.  
  9686.     # first look for base directory (COL, LST 2.2, CND 1.0, RedHat 3.0.3)
  9687.     if [ -d $DIR_PKGS/base ]; then
  9688.         Debug "directory $DIR_PKGS/base found"
  9689.         Debug "using cpio install mode"
  9690.         # raw cpio packages
  9691.         for pkgfile in $DIR_PKGS/base/fsstnd.cgz $DIR_PKGS/base/skeleton.cgz ; do
  9692.             Do_Uncpio $pkgfile
  9693.         done
  9694.         # remove directories to prevent moves to .save
  9695.         rm -fr $DIR_TARGET/root
  9696.         rm -fr $DIR_TARGET/etc/skel
  9697.         # adjust opt symlink if necessary
  9698.         Fix_opt
  9699.         # adjust library symlinks
  9700.         Fix_ldconfig
  9701.     fi
  9702.  
  9703.     # prefer install driven by pkgs.sel (COL 1.0, CND 1.0, RedHat 3.0.3)
  9704.     if [ -d $DIR_PKGS/RPMS ]; then
  9705.         Debug "file $DIR_PKGS/RPMS found"
  9706.         Debug "using RPMS install mode"
  9707.         for pkgname in `cat $FILE_PKGS_SEL` ; do
  9708.             Do_Find_File_To_Pkg $pkgname
  9709.             pkgfile="$PKG_FILE"
  9710.             Debug "Install $pkgname ($pkgfile)" 
  9711.             Do_Raw_rpm_Install $pkgfile $pkgname
  9712.         done
  9713.         if [ "$INSTALL_MODE" = "OpenLinux" ]; then
  9714.             Fix_12_Alpha before_postin
  9715.             Do_All_Postin
  9716.             Fix_12_Alpha after_postin
  9717.         fi
  9718.         return 0
  9719.     else
  9720.         Debug "no idea how to install $DIR_PKGS"
  9721.         return 1
  9722.     fi
  9723.     return 0
  9724. }
  9725.  
  9726.  
  9727. Do_Uncpio()
  9728. {
  9729.     local retval=
  9730.  
  9731.     mkdir -p $DIR_TARGET/tmp/LST
  9732.     echo "#!/bin/sh" > /tmp/LST/do_uncpio
  9733.     echo "cd $DIR_TARGET || exit 42" >> /tmp/LST/do_uncpio
  9734.     echo 'cat $1 | gzip -d | cpio -ivumd && exit 0' >> /tmp/LST/do_uncpio
  9735.     chmod 755 /tmp/LST/do_uncpio
  9736.  
  9737.     sync
  9738.     /tmp/LST/do_uncpio $1 2> $DIR_LOG_INSTALLED/`basename $1 .cgz` && return 0
  9739.     History_Install "do_uncpio $1 exited with error code <$?> (bad package ?)"
  9740.     Debug_Stop
  9741.     return 1
  9742. }
  9743.  
  9744. Do_4_Digit()
  9745. {
  9746.   local was="$1"
  9747.   local now=
  9748.  
  9749.   was="`echo $was | sed 's/^[0]*//'`" 
  9750.  
  9751.   if [ $was -gt 999 ]; then
  9752.     now="$was"
  9753.   elif [ $was -gt 99 ]; then
  9754.     now="0$was"
  9755.   elif [ $was -gt 9 ]; then
  9756.     now="00$was"
  9757.   else
  9758.     now="000$was"
  9759.   fi
  9760.   echo "$now"
  9761.   return 0
  9762. }
  9763.  
  9764. Do_Unrpm()
  9765. {
  9766.   local retval=
  9767.   local num=
  9768.   local num4digit=
  9769.  
  9770.   mkdir -p $DIR_TARGET/tmp/LST
  9771.   echo "#!/bin/sh" > /tmp/LST/do_unrpm
  9772.   if [ "$DIR_TARGET" = '/' ]; then
  9773.     echo "rpm -i --nodeps $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  9774.   else
  9775.     if [ "$INSTALL_MODE" = "OpenLinux" ]; then
  9776.       if [ -f /source/data/use-force ]; then
  9777.         echo "rpm -i --force --nodeps --noscripts --root $DIR_TARGET $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  9778.       else
  9779.         echo "rpm -i --nodeps --noscripts --root $DIR_TARGET $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  9780.       fi
  9781.     else
  9782.       if [ "$CND10_MODE" = "true" ]; then
  9783.         echo "cd $DIR_TARGET || exit 1" >> /tmp/LST/do_unrpm
  9784.         echo "rpmq -i $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  9785.       else
  9786.         echo "rpm -i --force --root $DIR_TARGET $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  9787.       fi
  9788.     fi
  9789.   fi
  9790.   echo "exit 1" >> /tmp/LST/do_unrpm
  9791.  
  9792.   chmod 755 /tmp/LST/do_unrpm
  9793.   cat /tmp/LST/do_unrpm > /dev/tty4
  9794.  
  9795.   sync
  9796.   /tmp/LST/do_unrpm $1 2> $DIR_LOG_ERRORS/$PKG_NAME
  9797.   retval=$?
  9798.   # remove empty error logs
  9799.   if [ ! -s $DIR_LOG_ERRORS/$PKG_NAME ]; then
  9800.     rm -f $DIR_LOG_ERRORS/$PKG_NAME
  9801.   fi
  9802.   if [ $retval -ne 0 ]; then
  9803.     History_Install "do_unrpm $1 exited with error code <$retval> (bad package ?)"
  9804.     # Debug_Stop
  9805.     Error --file $FILE_TMP_ERR "rpm install of $1 failed"
  9806.     return $retval
  9807.   else
  9808.     rm -f $FILE_TMP_ERR
  9809.   fi
  9810.  
  9811.   # extract post install script
  9812.   rpmextr --post $1 > $DIR_TARGET/install/doinst.sh
  9813.   if [ ! -s $DIR_TARGET/install/doinst.sh ]; then
  9814.     rm -f $DIR_TARGET/install/doinst.sh
  9815.   else
  9816.     chmod 755 $DIR_TARGET/install/doinst.sh
  9817.     cp -a $DIR_TARGET/install/doinst.sh $DIR_TARGET/install/scripts/$PKG_NAME.postin
  9818.     if [ "$DIR_TARGET" != '/' ]; then
  9819.       if [ "$INSTALL_MODE" = "OpenLinux" ]; then
  9820.         mkdir -p $DIR_TARGET/install/postin
  9821.         num="`do_calc $PKG_NUM_DONE + 1 `"
  9822.         num4digit="`Do_4_Digit $num`"
  9823.         cp -a $DIR_TARGET/install/doinst.sh $DIR_TARGET/install/postin/${num4digit}.${PKG_NAME}
  9824.       fi
  9825.     fi
  9826.   fi
  9827.   if [ "$CND10_MODE" != "true" ]; then
  9828.     rm -f $DIR_TARGET/install/doinst.sh
  9829.     # extract short and long listings
  9830.     rpm -ql $PKG_NAME > $DIR_TARGET/install/installed/$PKG_NAME
  9831.     rpm -qlv $PKG_NAME > $DIR_TARGET/install/contents/$PKG_NAME
  9832.   fi
  9833.   return 0
  9834. }
  9835.  
  9836.  
  9837. Fix_col22()
  9838. {
  9839.     # remove postin scripts that currently hang
  9840.     rm -f $DIR_TARGET/install/postin/*.kpilot
  9841.     mkdir -p $DIR_TARGET/var/run
  9842.     mkdir -p $DIR_TARGET/var/lock
  9843.     mkdir -p $DIR_TARGET/var/log
  9844. }
  9845.  
  9846. # FIXME12: this whole function should disappear
  9847. Fix_12_Alpha()
  9848. {
  9849.     local uname_r
  9850.     local uname_v
  9851.  
  9852.     if [ "$1" = "target_mounted" ]; then
  9853.         # create linux symlink if not there
  9854.         mkdir -p $DIR_TARGET/usr/src
  9855.         if [ ! -L $DIR_TARGET/usr/src/linux ]; then
  9856.             ln -s linux-"`uname -r`" $DIR_TARGET/usr/src/linux
  9857.         fi
  9858.     elif [ "$1" = "before_postin" ]; then
  9859.         if [ -f /source/data/use-mini-lisa ]; then
  9860.             # use mini-lisa because new one is under construction
  9861.             cp -a $DIR_TARGET/bin/lisa $DIR_TARGET/bin/lisa.big
  9862.             cp -a $DIR_BIN/mini-lisa $DIR_TARGET/bin/lisa
  9863.         fi
  9864.         Fix_ldconfig
  9865.         Fix_col22
  9866.     elif [ "$1" = "after_postin" ]; then
  9867.         if [ -f /source/data/use-mini-lisa ]; then
  9868.             # install new lisa
  9869.             mv $DIR_TARGET/bin/lisa $DIR_TARGET/bin/mini-lisa
  9870.             mv $DIR_TARGET/bin/lisa.big $DIR_TARGET/bin/lisa
  9871.         fi
  9872.  
  9873.         # override old lisa-2.4.0 that was still in lisa-3.0-1 RPM
  9874.         if [ "`get_val -f $DIR_TARGET/bin/lisa SCRIPT_VERSION`" = "2.4.0" ]; then
  9875.             cp -a /bin/lisa $DIR_TARGET/bin/lisa
  9876.         fi
  9877.  
  9878.         # try to adjust the modules load files again
  9879.         uname_r="`Get_uname_r`"
  9880.         uname_v="`Get_uname_v`"
  9881.         # create modules load files again if kernels differ
  9882.         if [ "$uname_v" != "`uname -v`" ]; then
  9883.             if [ -f $DIR_TARGET/etc/modules/`uname -r`/"`uname -v`".default ]; then
  9884.                 mkdir -p $DIR_TARGET/etc/modules/${uname_r}
  9885.                 cp -a $DIR_TARGET/etc/modules/`uname -r`/"`uname -v`".default $DIR_TARGET/etc/modules/${uname_r}/"${uname_v}".default 
  9886.             fi
  9887.             if [ -f $DIR_TARGET/etc/modules/`uname -r`/"`uname -v`".rootfs ]; then
  9888.                 mkdir -p $DIR_TARGET/etc/modules/${uname_r}
  9889.                 cp -a $DIR_TARGET/etc/modules/`uname -r`/"`uname -v`".rootfs $DIR_TARGET/etc/modules/${uname_r}/"$uname_v".rootfs
  9890.             fi
  9891.             # adjust the initrd again
  9892.             Set_modules_autoload
  9893.             Set_initrd
  9894.         fi
  9895.     fi
  9896. }
  9897.  
  9898. Do_All_Postin()
  9899. {
  9900.     local script
  9901.     local short
  9902.     local postin_retval
  9903.     local pkg
  9904.     local num_done=0
  9905.     local num_all=0
  9906.     local percent=0
  9907.     local label_header="`Do_Translate \":INFO_RPM_INSTALL_TITLE:\"` (postin)"
  9908.  
  9909.     mkdir $DIR_TARGET/install/postin.errors
  9910.     # calc number of postin scripts to execute
  9911.     num_all="`ls -l $DIR_TARGET/install/postin/* | get_info -l`"
  9912.     num_all="`do_calc $num_all - 1`"
  9913.     for script in $DIR_TARGET/install/postin/* ; do
  9914.         short="`basename $script`"
  9915.         if [ -f $script ]; then
  9916.             pkg="`echo $short | cut -c 6- `"
  9917.             # calc percentage done
  9918.             percent="`do_calc 100 \* $num_done`"
  9919.             percent="`do_calc $percent / $num_all`"
  9920.             # this would be the simple solution
  9921.             # Info "Processing postin scripts ($num_done/$num_all) ;  ;  Next script is from $pkg ; ; :INFO_WAIT:"
  9922.             $CMD_BOX --nobutton -P "$percent" --height 8 --width 60 -r --title "$label_header" --info "$pkg ($num_done/$num_all)"
  9923.             Debug "calling $script script"
  9924.             History_Install "calling $script ..." 
  9925.             ( cd $DIR_TARGET; chroot $DIR_TARGET sh -c install/postin/$short ) > $DIR_TARGET/install/postin.errors/$short 2>&1
  9926.             postin_retval=$?
  9927.             if [ $postin_retval -ne 0 ]; then
  9928.                     echo "`date` $DIR_TARGET/install/postin/$short failed ($postin_retval)" >> $DIR_TARGET/var/adm/LST/log/postin.failed
  9929.                     # Error "rpm postin of $short failed"
  9930.             fi
  9931.             # remove empty error logs
  9932.             if [ ! -s $DIR_TARGET/install/postin.errors/$short ]; then
  9933.                 rm -f $DIR_TARGET/install/postin.errors/$short
  9934.             fi
  9935.             num_done="`do_calc $num_done + 1`"
  9936.         fi
  9937.     done
  9938.     echo "`date` ======== initial install done ========" >> $DIR_TARGET/var/adm/LST/log/postin.failed
  9939.     echo "`date` ======== initial install done ========" >> $DIR_TARGET/var/adm/LST/log/install.failed
  9940.     echo "`date` ======== initial install done ========" >> $DIR_TARGET/var/adm/LST/log/install.success
  9941.     return 0
  9942. }
  9943.  
  9944.  
  9945. # raw installation of rpm pkgs
  9946. #
  9947.  
  9948. Do_Raw_rpm_Install()
  9949. {
  9950.   local my_lang="`get_val CONF_LST_LANG`"
  9951.   local dir=`dirname $1`
  9952.   local file=`basename $1`
  9953.   local full=$1
  9954.   local pkg=$2
  9955.   local script=
  9956.   local size=
  9957.   local dummy
  9958.   local rpmextr_info
  9959.   local pkg_info
  9960.   local pkg_size
  9961.   local label_header="`Do_Translate \":INFO_RPM_INSTALL_TITLE:\"`"
  9962.   local label_file="`Do_Translate \":LABEL_FILE:\"`"
  9963.   local label_info="`Do_Translate \":LABEL_INFO:\"`"
  9964.   local label_installed="`Do_Translate \":LABEL_INSTALLED:\"`"
  9965.   local rpm_retval=0
  9966.   local postin_retval=0
  9967.  
  9968.   Debug "processing package $file start"
  9969.   Debug -d "params: <$*>"
  9970.  
  9971.   Get_Pkg_Info $full
  9972.   pkg_size="`do_calc $PKG_SIZE / 1024`"
  9973.  
  9974.   sum_installed="$PKG_NUM_DONE/$PKG_NUM_ALL ($PKG_KB_DONE/$PKG_KB_ALL kB)"
  9975.   if [ "$PKG_KB_DONE" -gt 0 -a "$PKG_KB_ALL" -gt 0 ]; then
  9976.     percent="`do_calc 100 \* $PKG_KB_DONE`"
  9977.     percent="`do_calc $percent / $PKG_KB_ALL`"
  9978.   elif [ "$PKG_NUM_ALL" -gt 0 -a "$PKG_KB_ALL" -gt 0 ]; then
  9979.     percent="`do_calc 100 \* $PKG_NUM_DONE`"
  9980.     percent="`do_calc $percent / $PKG_NUM_ALL`"
  9981.   else
  9982.     percent=0
  9983.     sum_installed="$PKG_NUM_DONE ($PKG_KB_DONE kB)"
  9984.   fi
  9985.   # fix rounding bug if using kB instead of packages
  9986.   if [ "$percent" = "100" ]; then
  9987.       percent=99
  9988.   fi
  9989.  
  9990.   Get_Filesystem_Usage --install > $FILE_TMP_MSG
  9991.  
  9992.   if [ "$my_lang" = "de" ]; then
  9993.     menutitle="Dateisystem Gr÷▀e(kB) frei(kB) benutzt Mountpunkt"
  9994.   else
  9995.     menutitle="Filesystem   size(kB) free(kB)  used  mount point"
  9996.   fi
  9997.  
  9998.   # the rest is to be browsed...
  9999.   sed -e '1d' $FILE_TMP_MSG > $FILE_TMP_VAL
  10000.   Debug -D "FILE_TMP_VAL:"
  10001.   Debug -c cat $FILE_TMP_VAL
  10002.  
  10003.   $CMD_BOX --nobutton -P "$percent" -r --title "$label_header" --menutitle "$menutitle" --text "$label_file $file ($pkg_size kB) ; $label_installed $sum_installed ; ; $label_info $PKG_INFO" --browse $FILE_TMP_VAL
  10004.  
  10005.   History_Install "start installing ..."
  10006.   # FIXME: Do_Save_Conflicts should happen here 
  10007.   Debug "extracting $full"
  10008.   Do_Unrpm $full
  10009.   rpm_retval=$?
  10010.  
  10011.   for script in doinst.sh doafter.sh ; do
  10012.     if [ -f $DIR_TARGET/install/$script ]; then
  10013.       Debug "calling $script script"
  10014.       History_Install "calling $script ..." 
  10015.       if [ "$INSTALL_MODE" != "OpenLinux" ]; then
  10016.         ( cd $DIR_TARGET; chroot $DIR_TARGET sh -c install/$script ) 2>&1 | Debug -p
  10017.         postin_retval=$?
  10018.       fi
  10019.       mv $DIR_TARGET/install/$script $DIR_LOG_SCRIPTS/$PKG_NAME.$script
  10020.     fi
  10021.   done
  10022.   PKG_NUM_DONE=`do_calc $PKG_NUM_DONE + 1 `
  10023.   size="` do_calc $PKG_SIZE / 1024 `"
  10024.   PKG_KB_DONE=`do_calc $PKG_KB_DONE + $size `
  10025.   Debug "processing package $file done"
  10026.  
  10027.   if [ "$rpm_retval" != 0 -o "$postin_retval" != 0 ]; then
  10028.     History_Install "installation of $file failed ($rpm_retval/$postin_retval)"
  10029.     echo "`date` installation of $file failed ($rpm_retval/$postin_retval)" >> $DIR_TARGET/var/adm/LST/log/install.failed
  10030.     return 1
  10031.   else
  10032.     History_Install "installation sucessfully completed"
  10033.     echo "`date` installation of $file was ok ($rpm_retval/$postin_retval)" >> $DIR_TARGET/var/adm/LST/log/install.success
  10034.     return 0
  10035.   fi
  10036. }
  10037.  
  10038. Get_Install_Stat()
  10039. {
  10040.   if [ -s $FILE_PKGS_SEL ]; then
  10041.     export PKG_NUM_ALL="`get_info -lf $FILE_PKGS_SEL`"
  10042.     Debug "PKG_NUM_ALL=<$PKG_NUM_ALL>" 
  10043.   else
  10044.     export PKG_NUM_ALL=0
  10045.   fi
  10046.   if [ -s $FILE_PKGS_SEL -a -s $FILE_PKGS_DATA ]; then
  10047.     if [ -z "$NEEDSPACE" ]; then
  10048.       NEEDSPACE=0
  10049.     fi
  10050.     if [ "$NEEDSPACE" -eq "0" ]; then
  10051.       Info ":INFO_CALCULATING_PKG_SIZES:"
  10052.       build_menu -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA -S | cut -d':' -f 7 > /tmp/val
  10053.     else
  10054.       do_calc $NEEDSPACE / 1024 > /tmp/val
  10055.     fi
  10056.     export PKG_KB_ALL="`cat /tmp/val`"
  10057.     Debug "PKG_KB_ALL=<$PKG_KB_ALL>"
  10058.   else
  10059.     export PKG_KB_ALL=0
  10060.   fi
  10061.   export PKG_NUM_DONE=0
  10062.   export PKG_KB_DONE=0
  10063. }
  10064.  
  10065. Get_Pkg_Info()
  10066. {
  10067.   local f_name=Get_Pkg_Info
  10068.   local f_args=1 # (pkg_name/pkg_file) ->
  10069.   local tmpfile=/tmp/pkginfo.$$
  10070.   local my_lang="`get_val CONF_LST_LANG`"
  10071.   local pkg_dict=$FILE_PKGS_INDEX
  10072.   export PKG_SERVICE="unknown"
  10073.   export PKG_NAME="unknown"
  10074.   export PKG_SEL="unknown"
  10075.   export PKG_PRIO="unknown"
  10076.   export PKG_PRIORITY="unknown"
  10077.   export PKG_SIZE="unknown"
  10078.   export PKG_DISK="unknown"
  10079.   export PKG_USAGE="unknown"
  10080.   export PKG_VERS="unknown"
  10081.   export PKG_RELEASE="unknown"
  10082.   export PKG_GROUP="unknown"
  10083.   export PKG_SERVICE="unknown"
  10084.   export PKG_SERIES="unknown"
  10085.   export PKG_INFO="unknown"
  10086.   export PKG_COPYRIGHT="unknown"
  10087.   export PKG_SRC="unknown"
  10088.   export PKG_VENDOR="unknown"
  10089.   export PKG_DISTRIBUTION="unknown"
  10090.  
  10091.   Check_Args $f_name $f_args $# "$@" || return 255
  10092.  
  10093.   if [ -f /usr/lib/LST/$my_lang/pkgs.idx ]; then
  10094.     pkg_dict=/usr/lib/LST/$my_lang/pkgs.idx
  10095.   fi
  10096.  
  10097.   PKG_FILE="$1"
  10098.   Check_File $PKG_FILE
  10099.   if [ $? -eq 0 ]; then
  10100.     # arg was a file name
  10101.     Do_Find_Pkg_To_File $PKG_FILE || return 1
  10102.   else
  10103.     # arg probably was a pkg name
  10104.     PKG_NAME="$1"
  10105.     Do_Find_File_To_Pkg $PKG_NAME || return 1
  10106.   fi
  10107.  
  10108.   # Get specific pkg info
  10109.   case $PKG_TYPE in
  10110.   rpm)
  10111.     # get data from rpm header
  10112.     rpmextr --shell $PKG_FILE > $tmpfile
  10113.     . $tmpfile
  10114.     rm -f $tmpfile
  10115.     # get data from pkgs.db
  10116.     db_printf -n -m ":1:$PKG_NAME:" -p ":3:4:5:-6:7:" -f $FILE_PKGS_DATA > $tmpfile
  10117.     if [ -s $tmpfile ]; then
  10118.       read PKG_SEL PKG_PRIO PKG_SIZE PKG_DISK PKG_USAGE < $tmpfile
  10119.     fi
  10120.     rm -f $tmpfile
  10121.     ;;
  10122.   esac
  10123.  
  10124.   # get package description (multilingual)
  10125.   PKG_INFO="`Do_Translate \":$PKG_NAME:\" $pkg_dict`"
  10126.   if [ "$PKG_INFO" = ":$PKG_NAME:" ]; then
  10127.     PKG_INFO="`rpmextr --tag=info $file`"
  10128.     if [ -z "$PKG_INFO" ]; then
  10129.       PKG_INFO="unknown"
  10130.     fi
  10131.   fi
  10132.  
  10133.   # selected if it is in the selection list
  10134.   if [ -n "$FILE_PKGS_SEL" ]; then
  10135.     if [ -s $FILE_PKGS_SEL ]; then
  10136.       Check_Found "$PKG_NAME" "$FILE_PKGS_SEL"
  10137.       if [ $? -eq 0 ]; then
  10138.         PKG_SEL=j
  10139.       else
  10140.         PKG_SEL=n
  10141.       fi
  10142.     else
  10143.       PKG_SEL=
  10144.     fi
  10145.   fi
  10146.  
  10147.   # get real pkg usage
  10148.   if [ -z "$PKG_SIZE" ]; then
  10149.     PKG_SIZE="`gzip -l $PKG_FILE | fgrep '%' | cut -c 10-20`"
  10150.   fi
  10151.  
  10152.   # get real file size
  10153.   if [ -n "$PKG_FILE" ]; then
  10154.     PKG_USAGE="`filesize $PKG_FILE`"
  10155.   fi
  10156.  
  10157.   if [ -n "$PKG_PRIO" -a "$PKG_PRIO" != "unknown" ]; then
  10158.     PKG_PRIORITY="`Do_Translate \":TYPE_PRIO_$PKG_PRIO:\"`"
  10159.     if [ "$PKG_PRIORITY" = ":TYPE_PRIO_$PKG_PRIO:" ]; then
  10160.       PKG_PRIORITY="unknown"
  10161.     fi
  10162.   fi
  10163.  
  10164.   if [ -n "$PKG_DISK" -a "$PKG_DISK" != "unknown" ]; then
  10165.     PKG_SERIES="`echo $PKG_DISK | sed 's/[0-9]*$//'`"
  10166.   fi
  10167. }
  10168.  
  10169. # Get_Pkg_Type FILE
  10170. #
  10171. Get_Pkg_Type()
  10172. {
  10173.   local f_name=Get_Pkg_Type
  10174.   local f_args=1 # (file) -> PKG_TYPE, PKGEXT
  10175.   local pkgtype
  10176.   local pkgext
  10177.   export PKG_TYPE=unknown
  10178.   export PKGEXT=unknown
  10179.  
  10180.   Check_Args $f_name $f_args $# "$@" || return 255
  10181.  
  10182.   for pkgtype in rpm ; do
  10183.     case $pkgtype in
  10184.     rpm)
  10185.       if [ "`basename $1 .$pkgtype`" != "`basename $1`" ]; then
  10186.         PKGEXT="$pkgtype"
  10187.         PKG_TYPE="$pkgtype"
  10188.         return 0
  10189.       fi
  10190.       ;;
  10191.     esac
  10192.   done
  10193. # FIXME: fallback for trans.tbl mode -> assume rpm
  10194.   PKGEXT="rpm"
  10195.   PKG_TYPE="rpm"
  10196.   return 0
  10197.   Error "$1 ; :ERR_UNKNOWN_PKGTYPE:"
  10198.   return 1
  10199. }
  10200.  
  10201. Has_Selections()
  10202. {
  10203.   Check_File $FILE_PKGS_SEL && return 0
  10204.   Msg ":ERR_MISSING_SELECTIONS:"
  10205.   return 1        
  10206. }
  10207.  
  10208. Has_Source()
  10209. {
  10210.   if [ -z "$DIR_SOURCE" ]; then
  10211.     Error ":ERR_MISSING_SOURCE:"
  10212.     return 1        
  10213.   fi
  10214.   return 0
  10215. }
  10216.  
  10217. Has_Pkgs()
  10218. {
  10219.   if [ -z "$DIR_PKGS" ]; then
  10220.     Error ":ERR_MISSING_SOURCE:"
  10221.     return 1        
  10222.   fi
  10223.   if [ ! -d "$DIR_PKGS/RPMS" ]; then
  10224.     return 1
  10225.   fi
  10226.   return 0
  10227. }
  10228.  
  10229. # checks if target path is valid
  10230. #
  10231. Has_Target_Path()
  10232. {
  10233.   local f_name=Has_Target_Path
  10234.   local f_args=0 # DIR_TARGET ->
  10235.  
  10236.   Check_Args $f_name $f_args $# "$@" || return 255
  10237.   if [ -z "$DIR_TARGET" ]; then
  10238.     Error ":ERR_MISSING_TARGET_PATH:"
  10239.     return 1
  10240.   fi
  10241.   if [ ! -d "$DIR_TARGET" ]; then
  10242.     Error "$DIR_TARGET ; :ERR_INVALID_TARGET_PATH:"
  10243.     return 1
  10244.   fi
  10245.   return 0
  10246. }    
  10247.  
  10248.  
  10249. Do_Check_Freespace()
  10250. {
  10251.   local TOTALSPACE=
  10252.   local need_MB=
  10253.   local free_MB=
  10254.  
  10255.   # calculate the needed space
  10256.   Do_Calc_Needspace $FILE_PKGS_SEL
  10257.   Debug "NEEDSPACE='$NEEDSPACE'"
  10258.  
  10259.   # calculate the free space
  10260.   Do_Calc_Freespace $DIR_TARGET
  10261.  
  10262.   # to get on the save side, we require an additional SPARESPACE
  10263.   TOTALSPACE=`do_calc $NEEDSPACE + $SPARESPACE`
  10264.   Debug "TOTALSPACE='$TOTALSPACE', FREESPACE='$FREESPACE'"
  10265.   free_MB="`do_calc $FREESPACE / 1048576`"
  10266.   need_MB="`do_calc $TOTALSPACE / 1048576`"
  10267.   if [ "$free_MB" = "$need_MB" ]; then
  10268.     need_MB="`do_calc $need_MB + 1`"
  10269.   fi
  10270.   if [ $need_MB -gt $free_MB ]; then
  10271.     if [ $free_MB -gt 0 ]; then
  10272.       Warn "($need_MB MB > $free_MB MB) ; :ERR_USR_TOO_SMALL:" || return 1
  10273.     else
  10274.       Debug "Warning free_MB is negative ($free_MB) Integer overflow?"
  10275.     fi
  10276.   fi
  10277.   return 0
  10278. }
  10279.  
  10280. Menu_Pkg_Select()
  10281. {
  10282.   prep_use INSTALL || return 1
  10283.   prep_use RPM_INSTALL || return 1
  10284.   Has_Source || return 1
  10285.   Has_Target_Path || return 1
  10286.   Check_Pkg_Database || return 1
  10287.   Check_Pkg_Index || return 1
  10288.  
  10289.   Info ":INFO_WAIT:"
  10290.  
  10291.   while [ 1 ]; do
  10292.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" = "SBA" ]; then
  10293.       build_menu -n -p ":1:" -d $FILE_PKGS_DATA > /usr/lib/LST/pkgs.sel
  10294.       ANSWER="Menu_Pkg_Select_Preset sel"
  10295.     else
  10296.       if [ -f /usr/lib/LST/pkgs.sel ]; then
  10297.         Choose --prefix "MENU" --default "Menu_Pkg_Select_Preset sel" --build "Build_PKG_SELECT" PKG_SELECT || return 1
  10298.       else
  10299.         Choose --prefix "MENU" --default "Menu_Pkg_Select_Preset rec" --build "Build_PKG_SELECT" PKG_SELECT || return 1
  10300.       fi
  10301.     fi
  10302.     COMMAND="$ANSWER"
  10303.     $COMMAND || continue
  10304.  
  10305.     Do_Check_Freespace || continue
  10306.  
  10307.     break
  10308.   done 
  10309.   # save final package selection
  10310.   if [ -f $FILE_PKGS_SEL ]; then
  10311.       cp -a $FILE_PKGS_SEL > /usr/lib/LST/pkgs.sel
  10312.   fi
  10313.   return 0
  10314. }
  10315.  
  10316. Menu_Pkg_Select_Pkgs()
  10317. {
  10318.   rm -f $FILE_SERIES_SEL
  10319.   rm -f $FILE_PKGS_SEL
  10320.   Info_lite ":INFO_BUILDING_PKGLIST: :INFO_WAIT:"
  10321.   touch $FILE_PKGS_SEL
  10322.  
  10323.   # generate pkglist from pkgs.db
  10324.   build_menu -s basis -c 2 -f -d $FILE_PKGS_DATA > /tmp/LST/HOPE
  10325.   Choose --menutitle ":MENU_SHOW_PKGS_MENUTITLE:" --sumlist --build "Build_PKG" PKG_SELECT_PKGS || return 1
  10326.   mv $FILE_TMP_ANSWER $FILE_PKGS_SEL
  10327.  
  10328.   # generate serieslist from pkglist
  10329.   Info_lite ":INFO_UPDATING_SELECTIONS:"
  10330.   build_menu -U 0 -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA | db_printf -p ":-2:-3:" | fgrep -v ':0' | db_printf -p ":1:" > $FILE_SERIES_SEL
  10331.  
  10332.   return 0
  10333. }
  10334.  
  10335. Menu_Pkg_Select_Preset()
  10336. {
  10337.   local preset=$1
  10338.  
  10339.   # initially NEEDSPACE is in MB
  10340.   export NEEDSPACE=0
  10341.  
  10342.   # generate selection list depending on the preset type
  10343.   Get_Preset_Pkgs $preset > $FILE_PKGS_SEL
  10344.  
  10345.   # generate serieslist from pkglist
  10346.   Info_lite ":INFO_UPDATING_SELECTIONS:"
  10347.   build_menu -U 0 -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA | db_printf -p ":-2:-3:" | fgrep -v ':0' | db_printf -p ":1:" > $FILE_SERIES_SEL
  10348.  
  10349.   # ask for X Server if recommended pkgs
  10350.   if [ "$preset" = "minx" -o "$preset" = "small" -o "$preset" = "rec" ]; then
  10351.     while [ 1 ]; do
  10352.       Choose --sumlist --build "build_menu -f -u XSERV -d $FILE_PKGS_DATA" PKG_SELECT_SERVICES_XSERVER || return 1
  10353.       if [ ! -s $FILE_TMP_ANSWER ]; then
  10354.     Error ":ERR_NEED_AT_LEAST_ONE_XSERVER:"
  10355.     continue
  10356.       fi
  10357.       cat $FILE_TMP_ANSWER >> $FILE_PKGS_SEL
  10358.       break
  10359.     done
  10360.   fi
  10361.  
  10362.   return 0
  10363. }
  10364.  
  10365. Menu_Pkg_Select_Series()
  10366. {
  10367.   local series=
  10368.   local choice=
  10369.   local retval=
  10370.  
  10371.   # reset all selections
  10372.   Info_lite ":INFO_BUILDING_SERIESLIST:"
  10373.   rm -f $FILE_PKGS_SEL
  10374.   rm -f $FILE_SERIES_SEL
  10375.   for i in $LST_SERIES ; do
  10376.     rm -f $DIR_LST_TMP/$i.sel
  10377.   done
  10378.  
  10379.   # loop for all series
  10380.   while [ 1 ]; do
  10381.     Choose --menutitle ":MENU_SHOW_SERIES_MENUTITLE:" --menu --build Build_SERIES PKG_SELECT_SERIES
  10382.     retval=$?
  10383.     if [ $retval -eq 255 ]; then
  10384.       return 255
  10385.     fi
  10386.     if [ $retval -ne 0 ]; then
  10387.       # workaround for unclear continue/abort
  10388.       if [ -f $FILE_PKGS_SEL ]; then
  10389.         ANSWER=ENDE
  10390.       else
  10391.         return 1
  10392.       fi
  10393.     fi
  10394.     SERIES="$ANSWER"
  10395.     if [ "$ANSWER" = "USAGE" ]; then
  10396.       Show_Filesystem_Usage $DIR_TARGET
  10397.       continue
  10398.     fi
  10399.     if [ "$ANSWER" = "ENDE" ]; then
  10400.       if [ "$DIR_TARGET" = "/" ]; then
  10401.     return 0
  10402.       fi
  10403.       if [ -s $FILE_SERIES_SEL ]; then
  10404.     fgrep -x "basis" $FILE_SERIES_SEL >/dev/null
  10405.     if [ $? -eq 0 ]; then
  10406.       return 0
  10407.     fi
  10408.       fi
  10409.       Msg ":ERR_NO_BASIS_SELECTED:"
  10410.       continue
  10411.     fi
  10412.     Choose --build "Build_SELECT_PRIO $SERIES" SELECT_PRIO || continue
  10413.     CHOICE="$ANSWER"
  10414.     if [ "$CHOICE" = "0" ]; then
  10415.       if [ -s $DIR_LST_TMP/$SERIES.sel -a -s $FILE_PKGS_SEL ]; then
  10416.     fgrep -vxf $DIR_LST_TMP/$SERIES.sel $FILE_PKGS_SEL > $FILE_PKGS_SEL.tmp
  10417.     mv $FILE_PKGS_SEL.tmp $FILE_PKGS_SEL
  10418.       fi    
  10419.       rm -f $DIR_LST_TMP/$SERIES.sel
  10420.       if [ -s $FILE_SERIES_SEL -a -n "$SERIES" ]; then
  10421.     fgrep -vx "$SERIES" $FILE_SERIES_SEL > $FILE_SERIES_SEL.tmp
  10422.     mv $FILE_SERIES_SEL.tmp $FILE_SERIES_SEL
  10423.       fi
  10424.       continue
  10425.     fi
  10426.  
  10427.     Info_lite ":INFO_BUILDING_PKGLIST: :INFO_WAIT:"
  10428.     touch $FILE_PKGS_SEL
  10429.     if [ "$CHOICE" = "4" ]; then
  10430.       build_menu -T $FILE_PKGS_SEL -d $FILE_PKGS_DATA | build_menu -N -s $SERIES -T $DIR_LST_TMP/$SERIES.sel -f > /tmp/LST/HOPE
  10431.     else
  10432.       build_menu -T $FILE_PKGS_SEL -d $FILE_PKGS_DATA | build_menu -N -s $SERIES -c $CHOICE -f > /tmp/LST/HOPE
  10433.     fi
  10434.     Choose --menutitle ":MENU_SHOW_PKGS_MENUTITLE:" --sumlist --build "Build_PKG" PKG_SELECT_PKGS || continue 
  10435.  
  10436.     Info_lite ":INFO_UPDATING_SELECTIONS:"
  10437.     # update selectlist
  10438.     mv $FILE_TMP_ANSWER $DIR_LST_TMP/$SERIES.sel
  10439.     rm -f $FILE_PKGS_SEL
  10440.     for i in $LST_SERIES ; do
  10441.       if [ -s $DIR_LST_TMP/$i.sel ]; then
  10442.     cat $DIR_LST_TMP/$i.sel >> $FILE_PKGS_SEL
  10443.       else
  10444.     rm -f $DIR_LST_TMP/$i.sel
  10445.       fi
  10446.     done
  10447.     # update serieslist
  10448.     touch $FILE_SERIES_SEL
  10449.     if [ -z "`fgrep -x $SERIES $FILE_SERIES_SEL`" ]; then
  10450.       if [ "$SERIES" = "basis" ]; then
  10451.     echo "$SERIES" > $FILE_SERIES_SEL.tmp
  10452.     cat $FILE_SERIES_SEL >> $FILE_SERIES_SEL.tmp
  10453.     mv $FILE_SERIES_SEL.tmp $FILE_SERIES_SEL
  10454.       else
  10455.     echo "$SERIES" >> $FILE_SERIES_SEL
  10456.       fi
  10457.     fi
  10458.   done
  10459.  
  10460.   return 0
  10461. }
  10462.  
  10463.  
  10464. Menu_Pkg_Select_Services()
  10465. {
  10466.   local i=
  10467.   local servok=0
  10468.  
  10469.   local shadsel=0
  10470.   local xsel=0
  10471.   local docsel=0
  10472.   local textsel=0
  10473.   local gamessel=0
  10474.   local develsel=0
  10475.   local netsel=0
  10476.   local servsel=0
  10477.   local develdocsel=0
  10478.   local netshadsel=0
  10479.   local netdocsel=0
  10480.   local netservsel=0
  10481.   local xshadsel=0
  10482.   local xtextsel=0
  10483.   local xgamessel=0
  10484.   local xnetsel=0
  10485.   local xdevelsel=0
  10486.   local xdeveldocsel=0
  10487.  
  10488.   while [ 1 ]; do
  10489.     # reset all selections
  10490.     rm -f $FILE_PKGS_SEL
  10491.     i=
  10492.     shadsel=0
  10493.     xsel=0
  10494.     docsel=0
  10495.     textsel=0
  10496.     gamessel=0
  10497.     develsel=0
  10498.     netsel=0
  10499.     servsel=0
  10500.     develdocsel=0
  10501.     netshadsel=0
  10502.     netdocsel=0
  10503.     netservsel=0
  10504.     xshadsel=0
  10505.     xtextsel=0
  10506.     xgamessel=0
  10507.     xnetsel=0
  10508.     xdevelsel=0
  10509.     xdeveldocsel=0
  10510.  
  10511.     # offer all MAIN choices
  10512.     echo "MAIN" > $FILE_META_SEL
  10513.  
  10514.     # for now we need SHADOW by default
  10515.     echo "SHAD" >> $FILE_META_SEL
  10516.     shadsel=1
  10517.  
  10518.     # ask for additional services (meta level)
  10519.     $CMD_BOX --multi ":CHOOSE_SERVICES:" \
  10520. --help ":CHOOSE_SERVICES_HELP:" \
  10521. "X" ":TYPE_SERVICE_X:" S \
  10522. "DOC" ":TYPE_SERVICE_DOC:" S \
  10523. "TEXT" ":TYPE_SERVICE_TEXT:" S \
  10524. "GAMES" ":TYPE_SERVICE_GAMES:" U \
  10525. "DEVEL" ":TYPE_SERVICE_DEVEL:" U \
  10526. "NET" ":TYPE_SERVICE_NET:" U \
  10527. "SERV" ":TYPE_SERVICE_SERV:" U 2>> $FILE_META_SEL || return 1
  10528.  
  10529.     servok=
  10530.     # reset all selections
  10531.     rm -f $FILE_PKGS_SEL
  10532.  
  10533.     fgrep -x X $FILE_META_SEL > /dev/null
  10534.     if [ $? -eq 0 ]; then
  10535.       while [ 1 ]; do
  10536.     # ask for X Server
  10537.     Choose --sumlist --build "build_menu -f -u XSERV -d $FILE_PKGS_DATA" PKG_SELECT_SERVICES_XSERVER || return 1
  10538.     if [ ! -s $FILE_TMP_ANSWER ]; then
  10539.       Error ":ERR_NEED_AT_LEAST_ONE_XSERVER:"
  10540.       continue
  10541.     fi
  10542.     cat $FILE_TMP_ANSWER >> $FILE_PKGS_SEL
  10543.     servok=1
  10544.     break
  10545.       done
  10546.     else
  10547.       servok=1
  10548.     fi
  10549.  
  10550.     Info_lite ":INFO_BUILDING_SERVICELIST:"
  10551.  
  10552.     # analyse selections
  10553.     fgrep -x X $FILE_META_SEL > /dev/null && xsel=1
  10554.     fgrep -x DOC $FILE_META_SEL > /dev/null && docsel=1
  10555.     fgrep -x TEXT $FILE_META_SEL > /dev/null && textsel=1
  10556.     fgrep -x GAMES $FILE_META_SEL > /dev/null && gamessel=1
  10557.     fgrep -x DEVEL $FILE_META_SEL > /dev/null && develsel=1
  10558.     fgrep -x NET $FILE_META_SEL > /dev/null && netsel=1
  10559.     fgrep -x SERV $FILE_META_SEL > /dev/null && servsel=1
  10560.     
  10561.     # hardcoded rules ;-)
  10562.  
  10563.     # devel rules
  10564.     if [ $develsel -eq 1 -a $docsel -eq 1 ]; then
  10565.       develdocsel=1
  10566.       echo "DEVELDOC" >> $FILE_META_SEL
  10567.     fi
  10568.  
  10569.     #
  10570.     # net rules
  10571.     #
  10572.     if [ $netsel -eq 1 -a $shadsel -eq 1 ]; then
  10573.       netshadsel=1
  10574.       echo "NETSHAD" >> $FILE_META_SEL
  10575.     fi
  10576.     if [ $netsel -eq 1 -a $docsel -eq 1 ]; then
  10577.       netdocsel=1
  10578.       echo "NETDOC" >> $FILE_META_SEL
  10579.     fi
  10580.     if [ $netsel -eq 1 -a $servsel -eq 1 ]; then
  10581.       netservsel=1
  10582.       echo "NETSERV" >> $FILE_META_SEL
  10583.     fi
  10584.  
  10585.     #
  10586.     # X rules
  10587.     #
  10588.     if [ $xsel -eq 1 -a $shadsel -eq 1 ]; then
  10589.       xshadsel=1
  10590.       echo "XSHAD" >> $FILE_META_SEL
  10591.     fi
  10592.     if [ $xsel -eq 1 -a $textsel -eq 1 ]; then
  10593.       xtextsel=1
  10594.       echo "XTEXT" >> $FILE_META_SEL
  10595.     fi
  10596.     if [ $xsel -eq 1 -a $gamessel -eq 1 ]; then
  10597.       xgamessel=1
  10598.       echo "XGAMES" >> $FILE_META_SEL
  10599.     fi
  10600.     if [ $xsel -eq 1 -a $netsel -eq 1 ]; then
  10601.       xnetsel=1
  10602.       echo "XNET" >> $FILE_META_SEL
  10603.     fi
  10604.     if [ $xsel -eq 1 -a $develsel -eq 1 ]; then
  10605.       xdevelsel=1
  10606.       echo "XDEVEL" >> $FILE_META_SEL
  10607.     fi
  10608.     if [ $xsel -eq 1 -a $develdocsel -eq 1 ]; then
  10609.       xdeveldocsel=1
  10610.       echo "XDEVELDOC" >> $FILE_META_SEL
  10611.     fi
  10612.  
  10613.     # generate servicelist
  10614.     rm -f $FILE_SERVICES_SEL
  10615.     for i in `cat $FILE_META_SEL` ; do
  10616.       fgrep ":$i:" $FILE_META_DATA | cut -d':' -f 3 >> $FILE_SERVICES_SEL 
  10617.     done
  10618.  
  10619.     echo "$CMD_BOX -a --help \":MENU_PKG_SELECT_SERVICES_HELP:\" \\" > $FILE_TMP_COMMAND
  10620.     echo "--sumlist \":MENU_PKG_SELECT_SERVICES_TEXT:\" \\" >> $FILE_TMP_COMMAND
  10621.     for i in `cat $FILE_SERVICES_SEL` ; do
  10622.       Debug "# build_menu -S -f -u $i -d $FILE_PKGS_DATA"
  10623.       build_menu -S -f -u $i -d $FILE_PKGS_DATA >> $FILE_TMP_COMMAND
  10624.     done
  10625.     rm -f $FILE_SERVICES_SEL
  10626.     echo "2> $FILE_TMP_MSG" >> $FILE_TMP_COMMAND
  10627.     chmod 755 $FILE_TMP_COMMAND
  10628.  
  10629.     # choose services
  10630.     sh $FILE_TMP_COMMAND && break
  10631.   done
  10632.     
  10633.   Info_lite ":INFO_BUILDING_SERVICELIST:"
  10634.  
  10635.   # generate pkglist
  10636.   mv $FILE_TMP_MSG $FILE_SERVICES_SEL
  10637.   for i in `cat $FILE_SERVICES_SEL` ; do
  10638.     build_menu -u $i -n -p ":1:" -d $FILE_PKGS_DATA >> $FILE_PKGS_SEL
  10639.   done
  10640.  
  10641.   # generate serieslist from pkglist
  10642.   Info_lite ":INFO_UPDATING_SELECTIONS:"
  10643.   build_menu -U 0 -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA | db_printf -p ":-2:-3:" | fgrep -v ':0' | db_printf -p ":1:" > $FILE_SERIES_SEL
  10644.  
  10645.   return 0
  10646. }
  10647.  
  10648.  
  10649. # libLSTuser - user administration library shared between several scripts
  10650. #
  10651. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  10652. #
  10653.  
  10654.  
  10655. List_GROUP()
  10656. {
  10657.     db_printf -n -p ":-1:3:4:" -f $FILE_ETC_GROUP
  10658. }
  10659.  
  10660. Build_GROUP()
  10661. {
  10662.     List_GROUP | do_quote
  10663. }
  10664.  
  10665. Check_GID_Known()
  10666. {
  10667.     local f_name=Check_GID_Known
  10668.     local f_args=1 # (gid) ->
  10669.  
  10670.     Check_Args $f_name $f_args $# "$@" || return 255
  10671.     if [ -n "`cut -d':' -f 3 $FILE_ETC_GROUP | sed -n "/^$1$/p"`" ]
  10672.     then return 0
  10673.     else return 1
  10674.     fi
  10675. }
  10676.  
  10677. Check_Group_Known()
  10678. {
  10679.     local f_name=Check_Group_Known
  10680.     local f_args=1 # (groupname) ->
  10681.  
  10682.     Check_Args $f_name $f_args $# "$@" || return 255
  10683.     if [ -n "`sed -n "/^$1:/p" $FILE_ETC_GROUP`" ]
  10684.     then return 0
  10685.     else return 1
  10686.     fi
  10687. }
  10688.  
  10689. Check_UID_Known()
  10690. {
  10691.     local f_name=Check_UID_Known
  10692.     local f_args=1 # (uid) ->
  10693.  
  10694.     Check_Args $f_name $f_args $# "$@" || return 255
  10695.     if [ -n "`cut -d':' -f 3 $FILE_ETC_PASSWD | sed -n "/^$1$/p"`" ]; then
  10696.          return 0
  10697.     else
  10698.         return 1
  10699.     fi
  10700. }
  10701.  
  10702. Check_User_Known()
  10703. {
  10704.     local f_name=Check_User_Known
  10705.     local f_args=1 # (username) ->
  10706.  
  10707.     Check_Args $f_name $f_args $# "$@" || return 255
  10708.     if [ -n "`sed -n "/^$1:/p" $FILE_ETC_PASSWD`" ]; then
  10709.         return 0
  10710.     else
  10711.         return 1
  10712.     fi
  10713. }
  10714.  
  10715. Get_Next_UID()
  10716. {
  10717.     local start_uid=100
  10718.     local stop_uid=65534
  10719.     local curr_uid=$start_uid
  10720.  
  10721.     while [ 1 ]; do
  10722.         if Check_UID_Known $curr_uid ; then
  10723.             curr_uid="`do_calc $curr_uid + 1`"
  10724.         else
  10725.             break
  10726.         fi
  10727.         # stop searching at user nobody
  10728.         if [ $curr_uid -eq $stop_uid ]; then
  10729.             echo ""
  10730.             return 1
  10731.         fi
  10732.     done
  10733.     echo "$curr_uid"
  10734.     return 0
  10735. }
  10736.  
  10737. Menu_User_Add()
  10738. {
  10739.     local newusername=
  10740.     local newuseruid=
  10741.     local newusergroup=
  10742.     local newusergid=
  10743.     local newuserhome=
  10744.     local newusershell=
  10745.     local newusergecos=
  10746.     local homeprefix=
  10747.     local skipall=
  10748.   
  10749.     if [ $# -gt 0 -a "X$1" = 'X--first' ]; then
  10750.         newusername=col
  10751.         newuseruid=100
  10752.         newusergroup=users
  10753.         newusergid=100
  10754.         newuserhome=/home/col
  10755.         newusershell=/bin/bash
  10756.         newusergecos="Caldera OpenLinux User"
  10757.         homeprefix=/home
  10758.         #skipall=true
  10759.     fi
  10760.  
  10761.     # ask logname
  10762.     while [ 1 ]; do
  10763.         if [ "$skipall" = "true" ]; then
  10764.             break
  10765.         fi
  10766.         while [ 1 ]; do
  10767.             while [ 1 ]; do
  10768.                 Ask_String LOGNAME_USER $newusername || return 1
  10769.                 newusername="$ANSWER"
  10770.                 if [ "$newusername" != "`echo $newusername | sed 's/ //'`" ]; then
  10771.                     Error "<$newusername> ; a username may not contain any spaces."
  10772.                     continue
  10773.                 fi
  10774.                 if [ -n "$newusername" ]; then
  10775.                     break
  10776.                 fi
  10777.             done
  10778.             if Check_User_Known $newusername ; then
  10779.                 Error "$newusername ; :ERR_LOGNAME_EXISTS:"
  10780.                 continue
  10781.             else
  10782.                 break
  10783.             fi
  10784.         done
  10785.  
  10786.         # ask UID     
  10787.         while [ 1 ]; do
  10788.             if [ -z "$newuseruid" ]; then
  10789.                 newuseruid="`Get_Next_UID`"
  10790.             fi
  10791.             Ask_String UID_USER $newuseruid || return 1
  10792.             newuseruid="$ANSWER"
  10793.             if [ -z "$newuseruid" ]; then
  10794.                 continue
  10795.             fi
  10796.             if Check_UID_Known $newuseruid ; then
  10797.                 Error "$newuserid ; :ERR_UID_EXISTS:"
  10798.                 continue
  10799.             else
  10800.                 break
  10801.             fi
  10802.         done
  10803.  
  10804.         # ask group
  10805.         newusergroup="`Get_Val CONF_GROUP_DEFAULT`"
  10806.         Choose --build Build_GROUP GROUP_USER $newusergroup || return 1
  10807.         newusergroup="$ANSWER"
  10808.         newusergid="`sed -n "/^$newusergroup:/p" $FILE_ETC_GROUP | cut -d':' -f 3`"
  10809.  
  10810.         # ask home
  10811.         newuserhome="`Get_Val CONF_HOME_DEFAULT`"
  10812.         if [ -z "$newuserhome" ]; then
  10813.             newuserhome=/home
  10814.         fi
  10815.         newuserhome="$newuserhome/$newusername"
  10816.         Ask_String HOME_USER $newuserhome || return 1
  10817.         newuserhome="$ANSWER"
  10818.         homeprefix="`echo $newuserhome | sed 's,^\(.*\)/[^/]*,\1,'`"
  10819.  
  10820.         # ask shell
  10821.         newusershell="`Get_Val CONF_SHELL_DEFAULT`"
  10822.         Choose --build "List box SHELL" SHELL_USER $newusershell || return 1
  10823.         newusershell="$ANSWER"
  10824.  
  10825.         # ask comment field
  10826.         Ask_String COMMENT_USER "$newusergecos" || return 1
  10827.         newusergecos="$ANSWER"
  10828.         if [ -n "$newusergecos" ]; then
  10829.             gecos="-c \"$newusergecos\""
  10830.         fi
  10831.         break
  10832.     done
  10833.  
  10834.     # Note: expire date is still set statically to 31th Dec 1999 (-e 10956)
  10835.     # Ask_String EXPIRE_DATE $CONF_ACCOUNT_EXPIRE_DATE
  10836.     # expire_date="$ANSWER"
  10837.     expire_date="10956"
  10838.  
  10839.     prep_use /usr/sbin/useradd
  10840.     mkdir -p $homeprefix
  10841.  
  10842.     if [ -n "$newusergecos" ]; then
  10843.         useradd -g "$newusergid" -u "$newuseruid" -c "$newusergecos" -d "$newuserhome" -s "$newusershell" -m "$newusername" || continue
  10844.     else
  10845.         useradd -g "$newusergid" -u "$newuseruid" -d "$newuserhome" -s "$newusershell" -m "$newusername" || continue
  10846.     fi
  10847.  
  10848.     chmod 644 $DIR_TARGET/etc/passwd
  10849.  
  10850.     mkdir -p $DIR_TARGET/$newuserhome
  10851.     if [ -d $DIR_TARGET/etc/skel ]; then
  10852.         cp -a $DIR_TARGET/etc/skel/. $DIR_TARGET/$newuserhome
  10853.     fi
  10854.     chown -R $newuseruid.$newusergid $DIR_TARGET/$newuserhome
  10855.  
  10856.     LAST_USER="$newusername"
  10857.  
  10858.     Do_Set_Password $newusername
  10859.     return 0
  10860. }
  10861.  
  10862.  
  10863.